{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": [],
      "include_colab_link": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/nceder/qpb4e/blob/main/code/Chapter%2022/Chapter_22.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "# 22 Data over the network"
      ],
      "metadata": {
        "id": "JbcZSBoak2L5"
      }
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "zADPg73Bk0jg",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        },
        "outputId": "0ffac3af-2266-4ea4-d107-f0d63ed97e04"
      },
      "source": [
        "import ftplib\n",
        "ftp = ftplib.FTP('tgftp.nws.noaa.gov')\n",
        "ftp.login()"
      ],
      "execution_count": 45,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "'230 Login successful.'"
            ],
            "application/vnd.google.colaboratory.intrinsic+json": {
              "type": "string"
            }
          },
          "metadata": {},
          "execution_count": 45
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "GucjmtKuk0jj",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        },
        "outputId": "05a5099a-003f-49ed-9025-de92f4579102"
      },
      "source": [
        "ftp.cwd('data')"
      ],
      "execution_count": 46,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "'250 Directory successfully changed.'"
            ],
            "application/vnd.google.colaboratory.intrinsic+json": {
              "type": "string"
            }
          },
          "metadata": {},
          "execution_count": 46
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "fLnUieBSk0jk",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "acd22653-d075-4321-e8c5-a186d9a8c003"
      },
      "source": [
        "ftp.nlst()"
      ],
      "execution_count": 47,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "['climate',\n",
              " 'fnmoc',\n",
              " 'forecasts',\n",
              " 'hurricane_products',\n",
              " 'marine',\n",
              " 'mcf',\n",
              " 'national_products',\n",
              " 'nsd_bbsss.txt',\n",
              " 'nsd_cccc.txt',\n",
              " 'observations',\n",
              " 'products',\n",
              " 'public_statement',\n",
              " 'raw',\n",
              " 'records',\n",
              " 'rfc',\n",
              " 'summaries',\n",
              " 'tgftp_heartbeat',\n",
              " 'watches_warnings',\n",
              " 'zonecatalog.curr']"
            ]
          },
          "metadata": {},
          "execution_count": 47
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "rjNlbBVZk0jk",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "9c07364b-9ac7-4db2-bc82-1fd60df10c79"
      },
      "source": [
        "x = ftp.retrbinary('RETR observations/metar/decoded/KORD.TXT', open('KORD.TXT', 'wb').write)\n",
        "open('KORD.TXT', 'r').readlines()"
      ],
      "execution_count": 48,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "[\"CHICAGO O'HARE INTERNATIONAL, IL, United States (KORD) 41-59N 087-55W 200M\\n\",\n",
              " 'Nov 27, 2024 - 08:51 PM EST / 2024.11.28 0151 UTC\\n',\n",
              " 'Wind: from the N (350 degrees) at 10 MPH (9 KT):0\\n',\n",
              " 'Visibility: 10 mile(s):0\\n',\n",
              " 'Sky conditions: overcast\\n',\n",
              " 'Temperature: 37.9 F (3.3 C)\\n',\n",
              " 'Dew Point: 32.0 F (0.0 C)\\n',\n",
              " 'Relative Humidity: 78%\\n',\n",
              " 'Pressure (altimeter): 29.82 in. Hg (1009 hPa)\\n',\n",
              " 'ob: KORD 280151Z 35009KT 10SM SCT075 OVC200 03/00 A2982 RMK AO2 SLP102 T00330000\\n',\n",
              " 'cycle: 2\\n']"
            ]
          },
          "metadata": {},
          "execution_count": 48
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "## 22.1.3 Retrieving files over HTTP/HTTPS"
      ],
      "metadata": {
        "id": "IZo7BP8emG-E"
      }
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "0bithuDzk0jm",
        "outputId": "ab9c673f-14cf-4c21-f05f-7acb01b31209",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "source": [
        "import requests\n",
        "response = requests.get(\"http://www.metoffice.gov.uk/pub/data/weather/uk/climate/stationdata/heathrowdata.txt\")\n",
        "print(response.text)"
      ],
      "execution_count": 49,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Heathrow (London Airport)\r\n",
            "Location 507800E 176700N, Lat 51.479 Lon -0.449, 25m amsl\r\n",
            "Estimated data is marked with a * after the value.\r\n",
            "Missing data (more than 2 days missing in month) is marked by  ---.\r\n",
            "Sunshine data taken from an automatic Kipp & Zonen sensor marked with a #, otherwise sunshine data taken from a Campbell Stokes recorder.\r\n",
            "   yyyy  mm   tmax    tmin      af    rain     sun\r\n",
            "              degC    degC    days      mm   hours\r\n",
            "   1948   1    8.9     3.3    ---     85.0    ---\r\n",
            "   1948   2    7.9     2.2    ---     26.0    ---\r\n",
            "   1948   3   14.2     3.8    ---     14.0    ---\r\n",
            "   1948   4   15.4     5.1    ---     35.0    ---\r\n",
            "   1948   5   18.1     6.9    ---     57.0    ---\r\n",
            "   1948   6   19.1    10.3    ---     67.0    ---\r\n",
            "   1948   7   21.7    12.0    ---     21.0    ---\r\n",
            "   1948   8   20.8    11.7    ---     67.0    ---\r\n",
            "   1948   9   19.6    10.2    ---     35.0    ---\r\n",
            "   1948  10   14.9     6.0    ---     50.0    ---\r\n",
            "   1948  11   10.8     4.6    ---     44.0    ---\r\n",
            "   1948  12    8.8     3.8    ---     63.0    ---\r\n",
            "   1949   1    8.5     1.8       9    23.0    ---\r\n",
            "   1949   2   10.4     0.6      11    27.0    ---\r\n",
            "   1949   3    9.3     1.2      11    26.1    ---\r\n",
            "   1949   4   16.2     6.0       1    34.2    ---\r\n",
            "   1949   5   17.1     6.8       0    56.9    ---\r\n",
            "   1949   6   22.0    10.5       0     9.0    ---\r\n",
            "   1949   7   25.1    12.9       0    46.5    ---\r\n",
            "   1949   8   23.9    12.5       0    26.3    ---\r\n",
            "   1949   9   22.8    13.3       0    23.3    ---\r\n",
            "   1949  10   17.0     8.6       3   139.6    ---\r\n",
            "   1949  11   10.2     2.9       7    53.4    ---\r\n",
            "   1949  12    9.2     2.9       6    33.0    ---\r\n",
            "   1950   1    7.1     1.7      11    16.8    ---\r\n",
            "   1950   2    9.9     2.4       7    82.2    ---\r\n",
            "   1950   3   12.3     3.5       4    17.4    ---\r\n",
            "   1950   4   12.9     4.2       1    54.8    ---\r\n",
            "   1950   5   17.2     7.6       0    41.8    ---\r\n",
            "   1950   6   23.6    12.3       0    44.6    ---\r\n",
            "   1950   7   21.6    12.9       0    91.8    ---\r\n",
            "   1950   8   21.9    12.1       0    68.8    ---\r\n",
            "   1950   9   17.6    10.2       0    63.3    ---\r\n",
            "   1950  10   14.0     6.1       3    10.9    ---\r\n",
            "   1950  11    9.3     3.3       3   108.2    ---\r\n",
            "   1950  12    3.8    -1.0      18    40.2    ---\r\n",
            "   1951   1    7.3     1.5       7    71.3    ---\r\n",
            "   1951   2    7.0     0.8       6   121.4    ---\r\n",
            "   1951   3    8.4     1.7       6    86.0    ---\r\n",
            "   1951   4   12.3     3.0       3    60.6    ---\r\n",
            "   1951   5   15.0     7.0       0    53.0    ---\r\n",
            "   1951   6   20.5    10.0       0    26.9    ---\r\n",
            "   1951   7   23.0    12.9       0    33.8    ---\r\n",
            "   1951   8   20.2    12.3       0    95.5    ---\r\n",
            "   1951   9   19.2    11.3       0    66.3    ---\r\n",
            "   1951  10   14.6     6.0       2    23.5    ---\r\n",
            "   1951  11   11.8     6.2       1   132.6    ---\r\n",
            "   1951  12    8.9     3.1       7    36.9    ---\r\n",
            "   1952   1    6.2     0.4      13    47.0    ---\r\n",
            "   1952   2    6.7    -0.3      14    16.1    ---\r\n",
            "   1952   3   10.6     3.8       4    65.3    ---\r\n",
            "   1952   4   15.6     5.8       2    39.9    ---\r\n",
            "   1952   5   19.6     9.4       0    57.1    ---\r\n",
            "   1952   6   20.9    10.9       0    30.0    ---\r\n",
            "   1952   7   23.3    13.4       0    12.2    ---\r\n",
            "   1952   8   21.6    13.3       0    63.5    ---\r\n",
            "   1952   9   16.4     7.6       0    70.8    ---\r\n",
            "   1952  10   13.2     5.7       4    69.8    ---\r\n",
            "   1952  11    7.5     1.6       9    79.4    ---\r\n",
            "   1952  12    5.8    -0.2      15    66.0    ---\r\n",
            "   1953   1    5.6     0.6      14    21.2    ---\r\n",
            "   1953   2    7.5     1.0       9    31.4    ---\r\n",
            "   1953   3   11.1     1.0      12     8.5    ---\r\n",
            "   1953   4   13.1     4.3       0    53.7    ---\r\n",
            "   1953   5   18.7     8.9       0    32.4    ---\r\n",
            "   1953   6   19.8    10.8       0    34.8    ---\r\n",
            "   1953   7   21.0    12.1       0    75.3    ---\r\n",
            "   1953   8   22.6    12.6       0    39.0    ---\r\n",
            "   1953   9   19.5     9.8       0    47.4    ---\r\n",
            "   1953  10   14.7     7.1       0    65.7    ---\r\n",
            "   1953  11   11.3     5.2       0    28.6    ---\r\n",
            "   1953  12   10.0     5.1       1    13.3    ---\r\n",
            "   1954   1    5.9     0.3      15    23.5    ---\r\n",
            "   1954   2    6.1     0.4       8    51.5    ---\r\n",
            "   1954   3   10.4     3.0       5    51.3    ---\r\n",
            "   1954   4   13.2     2.8       2     8.9    ---\r\n",
            "   1954   5   16.8     7.6       0    52.6    ---\r\n",
            "   1954   6   18.6    10.7       0    95.3    ---\r\n",
            "   1954   7   19.2    11.7       0    62.1    ---\r\n",
            "   1954   8   19.8    11.5       0    87.5    ---\r\n",
            "   1954   9   18.0     9.6       0    58.1    ---\r\n",
            "   1954  10   16.2     8.9       1    54.1    ---\r\n",
            "   1954  11   11.2     3.6       5    95.5    ---\r\n",
            "   1954  12    9.7     3.4       5    46.6    ---\r\n",
            "   1955   1    5.6     0.4      11    50.2    ---\r\n",
            "   1955   2    5.0    -0.8      16    35.0    ---\r\n",
            "   1955   3    7.9     0.2      18    22.8    ---\r\n",
            "   1955   4   15.2     5.1       0     7.2    ---\r\n",
            "   1955   5   15.5     6.4       0   103.2    ---\r\n",
            "   1955   6   20.0    11.1       0    52.1    ---\r\n",
            "   1955   7   24.4    13.1       0     7.1    ---\r\n",
            "   1955   8   24.3    13.6       0    17.8    ---\r\n",
            "   1955   9   19.9     9.9       0    42.7    ---\r\n",
            "   1955  10   13.5     5.3       4    87.7    ---\r\n",
            "   1955  11   10.7     4.2       5    30.1    ---\r\n",
            "   1955  12    9.5     2.3       8    46.7    ---\r\n",
            "   1956   1    7.0     0.5      14    88.6    ---\r\n",
            "   1956   2    2.9    -3.6      22     2.3    ---\r\n",
            "   1956   3   11.0     2.7       9    15.0    ---\r\n",
            "   1956   4   12.1     2.4       3    29.1    ---\r\n",
            "   1956   5   19.1     7.1       0     4.2    ---\r\n",
            "   1956   6   18.5     9.6       0    41.5    ---\r\n",
            "   1956   7   20.9    12.8       0   130.5    ---\r\n",
            "   1956   8   18.8    10.9       0    99.5    ---\r\n",
            "   1956   9   19.2    11.7       0    50.0    ---\r\n",
            "   1956  10   13.8     6.0       0    74.1    ---\r\n",
            "   1956  11    9.3     2.5       7    10.1    ---\r\n",
            "   1956  12    8.2     3.5       5    70.3    ---\r\n",
            "   1957   1    8.7     2.7       5    39.5    53.0\r\n",
            "   1957   2    9.0     2.9       5    69.8    64.9\r\n",
            "   1957   3   13.9     5.7       2    25.4    96.7\r\n",
            "   1957   4   14.2     5.2       1     5.7   169.6\r\n",
            "   1957   5   16.2     6.5       0    21.3   195.0\r\n",
            "   1957   6   23.6    10.7       0    22.4   284.5\r\n",
            "   1957   7   22.5    13.8       0    87.0   152.3\r\n",
            "   1957   8   21.1    12.5       0    86.2   154.4\r\n",
            "   1957   9   17.6    10.1       0    51.7    88.5\r\n",
            "   1957  10   15.5     7.7       0    47.0    85.9\r\n",
            "   1957  11    9.4     4.3       2    59.5    67.5\r\n",
            "   1957  12    7.6     1.0      11    42.1    40.8\r\n",
            "   1958   1    6.8     0.9      10    64.3    40.1\r\n",
            "   1958   2    8.9     1.9      10    58.7    45.7\r\n",
            "   1958   3    8.1     1.1      10    26.0   105.2\r\n",
            "   1958   4   12.3     3.8       3    29.5   153.2\r\n",
            "   1958   5   17.3     7.8       0    59.5   189.2\r\n",
            "   1958   6   19.4    10.7       0   104.3   152.2\r\n",
            "   1958   7   21.7    12.9       0    51.9   190.5\r\n",
            "   1958   8   20.8    13.1       0    75.2   103.1\r\n",
            "   1958   9   20.0    12.1       0    83.8   134.8\r\n",
            "   1958  10   14.9     8.3       0    50.7    94.2\r\n",
            "   1958  11    9.7     4.4       1    50.7    40.8\r\n",
            "   1958  12    8.0     2.7       2    85.1    29.6\r\n",
            "   1959   1    5.7    -1.1      23    54.8    76.2\r\n",
            "   1959   2    7.4     1.2       7     2.4    54.8\r\n",
            "   1959   3   11.9     4.4       0    43.8   103.9\r\n",
            "   1959   4   14.2     6.3       0    52.9   139.1\r\n",
            "   1959   5   18.7     8.0       0    21.9   221.4\r\n",
            "   1959   6   22.1    11.1       0    16.2   231.6\r\n",
            "   1959   7   24.7    13.3       0    86.5   276.9\r\n",
            "   1959   8   24.2    13.7       0    27.6   240.0\r\n",
            "   1959   9   22.7    10.6       0     5.1   209.2\r\n",
            "   1959  10   17.8     8.5       0    46.9   150.1\r\n",
            "   1959  11   10.8     3.5       6    53.5    53.0\r\n",
            "   1959  12    9.3     3.0       1    75.7    30.2\r\n",
            "   1960   1    6.9     1.8      12    47.9    34.4\r\n",
            "   1960   2    7.9     1.6       7    48.0    80.1\r\n",
            "   1960   3   10.2     4.5       0    33.9    65.0\r\n",
            "   1960   4   14.3     4.6       1    12.4   156.1\r\n",
            "   1960   5   18.4     9.3       0    45.6   181.7\r\n",
            "   1960   6   22.1    12.1       0    42.8   248.6\r\n",
            "   1960   7   20.1    12.4       0    67.2   139.7\r\n",
            "   1960   8   20.3    11.8       0    60.8   150.9\r\n",
            "   1960   9   18.5    10.5       0    75.3   128.4\r\n",
            "   1960  10   14.2     8.2       0   155.5    75.2\r\n",
            "   1960  11   11.2     4.5       4    89.5    69.4\r\n",
            "   1960  12    6.9     2.1       5    56.5    44.5\r\n",
            "   1961   1    6.9     1.2      11    64.4    45.8\r\n",
            "   1961   2   10.3     4.9       0    55.1    56.0\r\n",
            "   1961   3   13.9     2.9       4     5.7   166.7\r\n",
            "   1961   4   15.0     7.1       0    50.8    73.5\r\n",
            "   1961   5   16.8     7.4       0    17.2   217.2\r\n",
            "   1961   6   21.7    10.5       0    29.2   229.3\r\n",
            "   1961   7   22.1    12.1       0    26.2   180.0\r\n",
            "   1961   8   21.7    12.6       0    47.6   158.8\r\n",
            "   1961   9   20.9    12.0       0    64.7   125.4\r\n",
            "   1961  10   15.6     7.6       1    56.8   117.2\r\n",
            "   1961  11    9.9     3.5       7    52.5    55.6\r\n",
            "   1961  12    6.8     0.2      17    88.6    46.2\r\n",
            "   1962   1    7.9     1.2       7    76.1    67.1\r\n",
            "   1962   2    7.6     1.4       7    12.6    67.1\r\n",
            "   1962   3    7.4    -0.6      16    35.8   111.4\r\n",
            "   1962   4   12.7     4.7       0    41.8   142.7\r\n",
            "   1962   5   15.0     7.1       0    29.6   157.9\r\n",
            "   1962   6   20.4     9.4       0     6.1   260.5\r\n",
            "   1962   7   20.6    12.1       0    82.8   135.0\r\n",
            "   1962   8   20.0    11.6       0    52.9   173.6\r\n",
            "   1962   9   17.8     9.6       0    88.4   152.0\r\n",
            "   1962  10   15.7     7.1       1    37.6   114.4\r\n",
            "   1962  11    9.1     3.2       8    41.7    33.6\r\n",
            "   1962  12    5.0    -1.1      22    52.8    64.1\r\n",
            "   1963   1    0.8    -4.6      28    12.9    38.4\r\n",
            "   1963   2    2.8    -2.2      24     6.6    72.2\r\n",
            "   1963   3   10.7     3.0       7    68.2    95.9\r\n",
            "   1963   4   13.6     5.7       1    52.1   123.2\r\n",
            "   1963   5   16.0     6.9       0    33.7   195.6\r\n",
            "   1963   6   20.8    11.3       0    48.3   193.4\r\n",
            "   1963   7   21.1    11.9       0    28.1   196.2\r\n",
            "   1963   8   19.8    11.7       0    53.4   138.6\r\n",
            "   1963   9   18.0    10.1       0    49.0   120.9\r\n",
            "   1963  10   14.8     8.2       0    34.7    85.4\r\n",
            "   1963  11   11.8     6.0       1   118.8    59.3\r\n",
            "   1963  12    5.4     0.0      16    16.1    44.1\r\n",
            "   1964   1    5.8     0.4       9    17.8    37.4\r\n",
            "   1964   2    7.6     2.0       7    16.8    59.2\r\n",
            "   1964   3    7.6     2.6       5    95.1    66.8\r\n",
            "   1964   4   12.8     5.4       2    73.5   126.1\r\n",
            "   1964   5   19.6     9.8       0    46.1   197.8\r\n",
            "   1964   6   19.3    11.2       0   110.1   164.1\r\n",
            "   1964   7   22.8    13.5       0    20.2   219.7\r\n",
            "   1964   8   22.3    12.7       0    21.2   215.7\r\n",
            "   1964   9   21.1    10.6       0    11.1   213.7\r\n",
            "   1964  10   13.7     5.3       1    29.2   126.2\r\n",
            "   1964  11   11.2     5.3       2    29.6    55.0\r\n",
            "   1964  12    7.1     0.9      12    29.9    48.6\r\n",
            "   1965   1    6.6     1.0      14    43.0    72.8\r\n",
            "   1965   2    5.9     0.9      11     8.3    32.5\r\n",
            "   1965   3   10.5     2.2       9    58.0   129.7\r\n",
            "   1965   4   13.4     4.8       0    44.8   138.6\r\n",
            "   1965   5   16.8     8.6       0    39.5   194.6\r\n",
            "   1965   6   19.7    11.0       0    54.6   184.7\r\n",
            "   1965   7   19.3    11.7       0    85.9   129.9\r\n",
            "   1965   8   20.8    11.9       0    55.9   184.7\r\n",
            "   1965   9   17.4     9.2       0   109.4   130.0\r\n",
            "   1965  10   16.2     7.5       1    18.8   129.1\r\n",
            "   1965  11    8.4     2.2       9    65.4    96.5\r\n",
            "   1965  12    8.4     1.7       9    87.3    54.0\r\n",
            "   1966   1    5.3     1.0      13    32.6    40.8\r\n",
            "   1966   2    9.3     4.4       1    73.4    27.0\r\n",
            "   1966   3   10.9     2.6       4    12.2   122.6\r\n",
            "   1966   4   12.2     5.4       0    98.6    88.7\r\n",
            "   1966   5   17.0     7.5       0    50.5   222.9\r\n",
            "   1966   6   21.8    12.2       0    66.7   205.4\r\n",
            "   1966   7   20.1    12.2       0    78.0   161.6\r\n",
            "   1966   8   20.6    11.6       0    86.2   199.7\r\n",
            "   1966   9   19.6    10.8       0    36.7   161.4\r\n",
            "   1966  10   14.7     8.6       0   122.1    81.3\r\n",
            "   1966  11    8.8     2.9       4    41.7    59.3\r\n",
            "   1966  12    9.3     2.2       6    62.5    36.3\r\n",
            "   1967   1    7.3     2.1      12    36.4    66.1\r\n",
            "   1967   2    9.3     2.6       7    48.6    89.5\r\n",
            "   1967   3   11.6     3.7       1    35.7   172.9\r\n",
            "   1967   4   12.5     4.4       1    44.1   138.2\r\n",
            "   1967   5   15.6     7.8       1   102.1   183.6\r\n",
            "   1967   6   20.1    10.3       0    51.0   210.0\r\n",
            "   1967   7   23.5    13.8       0    73.5   239.5\r\n",
            "   1967   8   21.5    12.7       0    47.4   182.9\r\n",
            "   1967   9   18.5    11.1       0    59.5   118.6\r\n",
            "   1967  10   15.0     8.8       0   103.8    99.1\r\n",
            "   1967  11    9.7     2.6       5    42.3    78.7\r\n",
            "   1967  12    7.2     1.3      11    54.0    61.3\r\n",
            "   1968   1    7.2     1.3      13    65.1    43.0\r\n",
            "   1968   2    5.7     0.2      13    25.3    67.2\r\n",
            "   1968   3   11.1     3.5       3    22.6   142.3\r\n",
            "   1968   4   13.7     4.4       4    44.2   188.4\r\n",
            "   1968   5   15.4     7.0       0    80.8   170.8\r\n",
            "   1968   6   20.6    11.5       0    54.9   172.5\r\n",
            "   1968   7   20.7    12.6       0    79.4   146.7\r\n",
            "   1968   8   20.2    12.6       0    68.2   121.1\r\n",
            "   1968   9   18.8    11.6       0   131.4   125.6\r\n",
            "   1968  10   16.5    10.7       0    64.2    78.5\r\n",
            "   1968  11    9.5     4.8       3    44.3    40.7\r\n",
            "   1968  12    5.4     1.0      12    74.9    30.7\r\n",
            "   1969   1    8.9     3.4       5    71.7    32.4\r\n",
            "   1969   2    4.9    -0.9      15    45.0    70.5\r\n",
            "   1969   3    8.0     1.3       7    56.0    66.8\r\n",
            "   1969   4   13.6     3.9       4    20.3   207.6\r\n",
            "   1969   5   17.1     8.6       0    59.5   149.1\r\n",
            "   1969   6   20.6    10.2       0    26.6   262.8\r\n",
            "   1969   7   23.9    13.9       0    68.7   229.2\r\n",
            "   1969   8   21.8    13.6       0    93.0   141.3\r\n",
            "   1969   9   19.6    11.7       0     3.1   118.5\r\n",
            "   1969  10   18.2     9.9       0     5.1   117.3\r\n",
            "   1969  11    9.6     3.3       7    68.7    71.1\r\n",
            "   1969  12    6.1     1.4       9    46.1    18.5\r\n",
            "   1970   1    7.1     2.1       9    67.7    31.9\r\n",
            "   1970   2    7.2     0.8      12    39.9   105.5\r\n",
            "   1970   3    8.1     0.7      13    37.6    99.7\r\n",
            "   1970   4   11.4     3.7       3    59.5   122.7\r\n",
            "   1970   5   19.2     9.2       0    25.1   219.2\r\n",
            "   1970   6   23.6    12.7       0    70.1   273.3\r\n",
            "   1970   7   21.3    12.3       0    53.0   181.3\r\n",
            "   1970   8   22.3    13.0       0    53.6   184.3\r\n",
            "   1970   9   20.3    11.4       0    49.8   157.0\r\n",
            "   1970  10   15.7     8.1       0    10.4   100.9\r\n",
            "   1970  11   11.9     5.5       1   151.2    59.8\r\n",
            "   1970  12    7.0     1.7      10    38.5    45.3\r\n",
            "   1971   1    7.8     2.8       6    70.5    42.5\r\n",
            "   1971   2    8.6     1.9       5    16.6    72.6\r\n",
            "   1971   3    9.1     2.3       7    42.4   104.7\r\n",
            "   1971   4   12.2     4.8       1    47.3   121.5\r\n",
            "   1971   5   18.1     8.2       0    76.7   232.9\r\n",
            "   1971   6   17.8    10.1       0   127.7   145.4\r\n",
            "   1971   7   24.1    13.8       0    19.3   224.1\r\n",
            "   1971   8   21.3    13.5       0    64.4   147.5\r\n",
            "   1971   9   20.7    10.2       0    11.1   173.9\r\n",
            "   1971  10   17.2     8.1       0    57.6   147.0\r\n",
            "   1971  11   10.4     3.0       7    63.9    96.3\r\n",
            "   1971  12    9.3     4.5       1    21.0    31.4\r\n",
            "   1972   1    6.9     2.1       6    55.3    40.9\r\n",
            "   1972   2    7.9     2.6       2    43.4    35.0\r\n",
            "   1972   3   12.4     3.3       2    54.0   144.5\r\n",
            "   1972   4   12.9     5.7       0    38.3   120.8\r\n",
            "   1972   5   16.0     7.6       0    25.9   171.7\r\n",
            "   1972   6   17.5     9.0       0    15.4   166.3\r\n",
            "   1972   7   22.3    12.7       0    27.2   151.4\r\n",
            "   1972   8   21.8    12.1       0    15.4   190.0\r\n",
            "   1972   9   17.3     9.0       0    27.6   117.5\r\n",
            "   1972  10   15.6     8.5       0    17.3   112.7\r\n",
            "   1972  11    9.9     3.2       9    57.7    78.0\r\n",
            "   1972  12    9.4     3.5       2    66.7    56.5\r\n",
            "   1973   1    7.3     2.0      10    13.1    28.0\r\n",
            "   1973   2    8.1     0.7      15    12.5    66.0\r\n",
            "   1973   3   11.5     2.2       6    10.4   138.1\r\n",
            "   1973   4   12.5     3.9       2    58.1   140.5\r\n",
            "   1973   5   16.9     8.6       0    54.2   167.2\r\n",
            "   1973   6   21.9    11.6       0    68.8   254.5\r\n",
            "   1973   7   21.4    12.7       0    49.1   173.7\r\n",
            "   1973   8   23.7    13.8       0    40.9   189.1\r\n",
            "   1973   9   20.7    11.6       0    60.7   180.4\r\n",
            "   1973  10   13.9     6.1       0    38.6    98.9\r\n",
            "   1973  11   10.3     2.5      11    26.6    87.0\r\n",
            "   1973  12    8.6     2.1       9    52.3    59.6\r\n",
            "   1974   1    9.6     3.6       2    53.0    46.0\r\n",
            "   1974   2    9.2     3.0       2    57.8    67.2\r\n",
            "   1974   3   10.3     2.8       4    27.2   101.3\r\n",
            "   1974   4   14.0     4.7       0    15.2   159.3\r\n",
            "   1974   5   17.0     7.5       0    22.4   196.4\r\n",
            "   1974   6   20.1    10.6       0    67.2   201.7\r\n",
            "   1974   7   20.9    12.5       0    29.8   187.7\r\n",
            "   1974   8   21.5    12.1       0    67.8   190.3\r\n",
            "   1974   9   17.5     9.5       0   140.0   156.0\r\n",
            "   1974  10   11.0     5.0       1    71.9    89.1\r\n",
            "   1974  11   10.6     5.0       0   142.8    42.7\r\n",
            "   1974  12   11.0     5.6       0    34.4    52.6\r\n",
            "   1975   1   10.3     4.5       2    92.3    38.0\r\n",
            "   1975   2    9.3     1.9       5    23.0    79.1\r\n",
            "   1975   3    8.4     2.8       7    69.7    66.9\r\n",
            "   1975   4   13.3     5.0       5    43.6   133.4\r\n",
            "   1975   5   15.1     6.9       0    62.9   149.8\r\n",
            "   1975   6   21.8    10.4       0    23.2   293.7\r\n",
            "   1975   7   24.1    14.1       0    36.3   217.3\r\n",
            "   1975   8   25.9    15.0       0    13.3   226.0\r\n",
            "   1975   9   19.5    10.6       0   111.2   144.1\r\n",
            "   1975  10   14.4     7.0       0    23.2   111.6\r\n",
            "   1975  11   10.1     3.2       6    58.0    78.8\r\n",
            "   1975  12    7.6     1.5      11    29.1    40.3\r\n",
            "   1976   1    8.8     3.0       8    13.9    68.3\r\n",
            "   1976   2    7.8     2.3       7    21.1    39.7\r\n",
            "   1976   3    9.5     2.0       8    11.3   127.1\r\n",
            "   1976   4   13.7     4.3       1     9.9   182.3\r\n",
            "   1976   5   19.3     8.9       0    19.3   209.2\r\n",
            "   1976   6   25.5    13.7       0     6.3   261.2\r\n",
            "   1976   7   26.6    14.9       0    15.4   263.5\r\n",
            "   1976   8   25.1    13.2       0    16.4   263.7\r\n",
            "   1976   9   19.0    11.2       0    96.6   118.9\r\n",
            "   1976  10   14.9     8.8       0    93.0    61.4\r\n",
            "   1976  11    9.9     3.5       5    81.7    60.1\r\n",
            "   1976  12    5.6    -0.2      11    72.3    57.4\r\n",
            "   1977   1    6.1     0.8      15    63.5    38.2\r\n",
            "   1977   2    9.6     3.4       3    65.3    83.3\r\n",
            "   1977   3   11.2     4.5       4    56.8   105.1\r\n",
            "   1977   4   12.2     4.1       4    32.7   151.1\r\n",
            "   1977   5   16.4     7.2       0    37.3   210.5\r\n",
            "   1977   6   17.4     9.6       0    52.4   134.8\r\n",
            "   1977   7   22.4    12.7       0    10.4   210.4\r\n",
            "   1977   8   20.3    13.0       0   150.3   135.8\r\n",
            "   1977   9   18.0    10.7       0    15.3   117.5\r\n",
            "   1977  10   16.3     9.0       0    48.1   113.8\r\n",
            "   1977  11   10.4     4.6       2    51.3    88.4\r\n",
            "   1977  12    9.2     4.1       2    55.5    37.1\r\n",
            "   1978   1    6.7     0.7      11    68.8    47.4\r\n",
            "   1978   2    6.2     0.7      13    40.9    41.3\r\n",
            "   1978   3   11.3     3.5       4    58.9   108.5\r\n",
            "   1978   4   10.7     3.9       4    45.4   113.8\r\n",
            "   1978   5   17.2     7.9       0    78.5   210.6\r\n",
            "   1978   6   19.7    10.7       0    38.1   175.9\r\n",
            "   1978   7   20.5    12.7       0    65.5   142.0\r\n",
            "   1978   8   20.7    12.1       0    53.6   177.6\r\n",
            "   1978   9   20.1    10.8       0    17.1   166.7\r\n",
            "   1978  10   17.1     8.4       0     1.6    98.4\r\n",
            "   1978  11   12.6     6.2       4     8.2    81.7\r\n",
            "   1978  12    7.8     2.6      11   108.6    35.4\r\n",
            "   1979   1    3.8    -2.6      24    59.9    58.5\r\n",
            "   1979   2    4.5    -0.4      13    44.0    52.9\r\n",
            "   1979   3    9.2     2.0       4    94.9    99.6\r\n",
            "   1979   4   12.7     4.8       2    77.6   106.3\r\n",
            "   1979   5   15.9     7.2       2    87.0   200.6\r\n",
            "   1979   6   19.0    11.1       0    37.6   140.3\r\n",
            "   1979   7   22.5    13.4       0    21.7   182.5\r\n",
            "   1979   8   21.0    12.2       0    33.4   171.3\r\n",
            "   1979   9   19.6    10.3       0    20.8   177.6\r\n",
            "   1979  10   16.4     8.8       0    68.7   124.9\r\n",
            "   1979  11   10.8     3.5       5    48.2    58.1\r\n",
            "   1979  12    9.2     3.9       5    90.7    49.6\r\n",
            "   1980   1    6.0    -0.1      14    29.7    72.4\r\n",
            "   1980   2    9.9     2.9       4    36.8    52.2\r\n",
            "   1980   3    9.0     2.4       4    72.1    83.2\r\n",
            "   1980   4   14.0     5.4       0    21.6   161.2\r\n",
            "   1980   5   17.3     7.4       0    26.1   221.1\r\n",
            "   1980   6   19.8    10.9       0   106.2   188.8\r\n",
            "   1980   7   19.7    11.9       0    59.3   163.7\r\n",
            "   1980   8   21.9    13.3       0    52.3   173.4\r\n",
            "   1980   9   20.1    12.0       0    27.7   146.6\r\n",
            "   1980  10   14.0     5.8       0    96.5   123.3\r\n",
            "   1980  11    9.3     4.5       4    26.4    66.4\r\n",
            "   1980  12    8.9     2.7       8    33.4    63.7\r\n",
            "   1981   1    8.1     2.0       9    32.7    62.0\r\n",
            "   1981   2    7.1    -0.1      16    11.9    71.6\r\n",
            "   1981   3   11.8     6.5       1    90.8    56.8\r\n",
            "   1981   4   12.9     4.9       1    32.4   129.9\r\n",
            "   1981   5   16.1     8.4       0    79.8   112.0\r\n",
            "   1981   6   18.5    10.4       0    39.5   152.1\r\n",
            "   1981   7   22.0    12.8       0    56.7   148.9\r\n",
            "   1981   8   22.8    13.0       0    45.3   217.9\r\n",
            "   1981   9   20.3    11.3       0    94.6   151.1\r\n",
            "   1981  10   12.9     5.8       0    76.5   110.3\r\n",
            "   1981  11   11.5     5.1       1    34.1    54.9\r\n",
            "   1981  12    4.4    -1.5      17    85.3    47.0\r\n",
            "   1982   1    6.9     0.4      14    38.0    57.7\r\n",
            "   1982   2    8.4     2.4       4    31.6    51.3\r\n",
            "   1982   3   11.1     2.5       3    51.5   171.3\r\n",
            "   1982   4   14.3     5.0       2    22.8   180.9\r\n",
            "   1982   5   18.0     7.6       0    71.9   204.8\r\n",
            "   1982   6   21.5    12.8       0    84.6   182.1\r\n",
            "   1982   7   22.7    13.4       0    24.5   164.0\r\n",
            "   1982   8   22.2    12.9       0    39.7   168.9\r\n",
            "   1982   9   20.8    11.1       0    39.6   156.0\r\n",
            "   1982  10   14.1     7.8       0   109.1    69.6\r\n",
            "   1982  11   11.4     6.2       3    72.9    55.5\r\n",
            "   1982  12    8.2     1.9       8    63.6    50.0\r\n",
            "   1983   1   10.0     4.3       3    47.2    51.4\r\n",
            "   1983   2    5.5    -0.5      19    31.0    85.3\r\n",
            "   1983   3   10.8     3.0       5    33.7    93.4\r\n",
            "   1983   4   12.4     3.6       3   101.5   145.4\r\n",
            "   1983   5   15.6     7.5       0    72.9   136.8\r\n",
            "   1983   6   20.8    11.4       0    12.0   188.8\r\n",
            "   1983   7   27.6    16.0       0    50.3   247.8\r\n",
            "   1983   8   24.5    13.8       0    11.4   219.1\r\n",
            "   1983   9   19.3    11.3       0    42.9   113.7\r\n",
            "   1983  10   15.1     7.6       2    41.7   114.0\r\n",
            "   1983  11   11.3     5.5       4    39.5    42.9\r\n",
            "   1983  12    9.2     2.7      10    50.9    58.5\r\n",
            "   1984   1    8.0     1.4       9    73.3    88.1\r\n",
            "   1984   2    7.4     1.3      10    32.9    71.6\r\n",
            "   1984   3    8.9     2.5       2    73.4    51.4\r\n",
            "   1984   4   14.6     3.9       5     5.4   230.5\r\n",
            "   1984   5   14.9     6.8       0    90.9   144.7\r\n",
            "   1984   6   21.3    11.3       0    36.1   237.0\r\n",
            "   1984   7   24.2    12.9       0    19.2   232.5\r\n",
            "   1984   8   24.4    14.2       0    27.8   201.1\r\n",
            "   1984   9   18.6    11.0       0    73.4    98.1\r\n",
            "   1984  10   15.8     8.5       0    82.8    91.2\r\n",
            "   1984  11   12.2     6.4       0    69.8    75.4\r\n",
            "   1984  12    8.7     2.8       8    56.7    49.3\r\n",
            "   1985   1    4.1    -1.8      20    41.3    46.9\r\n",
            "   1985   2    6.3     0.1      13    29.8    78.3\r\n",
            "   1985   3    9.4     1.3      12    34.1   105.2\r\n",
            "   1985   4   14.0     5.3       3    33.3   157.5\r\n",
            "   1985   5   16.4     8.2       0    64.7   163.7\r\n",
            "   1985   6   18.5     9.9       0    88.9   167.2\r\n",
            "   1985   7   22.9    13.2       0    35.2   241.4\r\n",
            "   1985   8   20.3    11.9       0    58.9   187.3\r\n",
            "   1985   9   20.6    11.4       0    11.2   143.4\r\n",
            "   1985  10   16.1     8.8       0    18.4   118.8\r\n",
            "   1985  11    8.1     1.2      11    30.0    88.6\r\n",
            "   1985  12   10.0     5.2       4    80.5    39.0\r\n",
            "   1986   1    7.2     1.0      11   105.6    62.8\r\n",
            "   1986   2    1.7    -2.7      24    14.5    61.9\r\n",
            "   1986   3   10.1     1.8       8    43.5   124.4\r\n",
            "   1986   4   10.9     3.2       3    60.7   135.2\r\n",
            "   1986   5   16.3     7.9       0    52.3   172.3\r\n",
            "   1986   6   21.8    11.4       0    17.2   225.8\r\n",
            "   1986   7   22.6    13.3       0    54.6   180.5\r\n",
            "   1986   8   20.0    11.5       0    66.7   158.3\r\n",
            "   1986   9   17.4     8.1       0    22.8   157.5\r\n",
            "   1986  10   16.4     8.5       0    72.4   116.3\r\n",
            "   1986  11   12.1     5.2       0    66.1    73.1\r\n",
            "   1986  12    9.7     3.2       4    60.6    55.1\r\n",
            "   1987   1    3.6    -1.0      18    11.1    54.4\r\n",
            "   1987   2    7.7     1.4      12    32.4    58.0\r\n",
            "   1987   3    8.5     1.4      14    42.7   105.2\r\n",
            "   1987   4   15.8     6.7       0    39.9   153.0\r\n",
            "   1987   5   16.3     7.0       0    54.1   198.2\r\n",
            "   1987   6   18.6    10.6       0    69.9   132.9\r\n",
            "   1987   7   21.8    13.2       0    77.3   176.1\r\n",
            "   1987   8   21.8    12.5       0    57.2   172.3\r\n",
            "   1987   9   19.3    11.4       0    36.9   147.2\r\n",
            "   1987  10   15.0     7.7       0   174.8   120.6\r\n",
            "   1987  11    9.8     4.2       3    43.3    39.8\r\n",
            "   1987  12    8.9     4.1       5    14.4    34.4\r\n",
            "   1988   1    8.8     3.1       5   106.9    54.7\r\n",
            "   1988   2    8.7     1.8       6    26.0   115.9\r\n",
            "   1988   3   10.7     3.7       4    59.5    88.1\r\n",
            "   1988   4   13.5     5.1       1    27.7   145.8\r\n",
            "   1988   5   18.0     9.1       0    41.6   202.0\r\n",
            "   1988   6   19.7    11.3       0    44.3   159.9\r\n",
            "   1988   7   20.0    12.2       0    76.2   161.7\r\n",
            "   1988   8   21.8    12.4       0    60.9   195.0\r\n",
            "   1988   9   18.8    10.8       0    27.8   147.8\r\n",
            "   1988  10   15.5     8.5       0    56.3   110.0\r\n",
            "   1988  11    9.9     1.8      12    16.0    89.2\r\n",
            "   1988  12   10.4     4.8       1     8.9    37.5\r\n",
            "   1989   1    9.5     3.1       6    26.0    59.2\r\n",
            "   1989   2   10.2     2.6       4    40.2    94.2\r\n",
            "   1989   3   12.9     4.5       2    56.6   100.0\r\n",
            "   1989   4   11.5     4.3       1    64.2   144.5\r\n",
            "   1989   5   21.0    10.0       0    12.1   310.1\r\n",
            "   1989   6   22.1    11.4       0    35.5   258.5\r\n",
            "   1989   7   25.8    14.8       0    36.7   274.8\r\n",
            "   1989   8   24.2    13.1       0    55.7   267.1\r\n",
            "   1989   9   20.7    12.6       0    10.8   131.2\r\n",
            "   1989  10   17.1     9.7       0    52.8   113.4\r\n",
            "   1989  11   10.9     3.7       6    23.8   107.0\r\n",
            "   1989  12    9.4     4.2       2   119.3    33.6\r\n",
            "   1990   1   10.2     4.4       0    71.1    57.6\r\n",
            "   1990   2   11.7     5.3       1    92.3    94.3\r\n",
            "   1990   3   13.6     4.8       1     6.9   154.6\r\n",
            "   1990   4   14.6     4.2       3    29.7   245.0\r\n",
            "   1990   5   20.5     9.0       0     4.1   287.0\r\n",
            "   1990   6   19.5    10.8       0    39.5   132.5\r\n",
            "   1990   7   24.7    13.2       0     6.9   273.2\r\n",
            "   1990   8   26.0    14.7       0    26.8   249.3\r\n",
            "   1990   9   19.7    10.0       0    24.9   173.4\r\n",
            "   1990  10   16.9     9.6       0    49.7   122.5\r\n",
            "   1990  11   10.7     5.1       0    22.1    70.0\r\n",
            "   1990  12    7.6     2.5       7    51.4    47.8\r\n",
            "   1991   1    7.3     1.8       3    69.7    68.4\r\n",
            "   1991   2    5.4    -1.3      16    34.7    48.5\r\n",
            "   1991   3   12.5     5.3       2    25.9   102.7\r\n",
            "   1991   4   13.1     4.8       2    52.8   158.5\r\n",
            "   1991   5   15.7     7.7       0     9.1   138.7\r\n",
            "   1991   6   17.8     9.7       0    88.6   135.0\r\n",
            "   1991   7   23.2    14.4       0    92.9   218.6\r\n",
            "   1991   8   24.1    14.4       0    26.0   241.7\r\n",
            "   1991   9   21.4    11.5       0    43.7   183.0\r\n",
            "   1991  10   14.6     7.6       0    18.5    87.1\r\n",
            "   1991  11   10.6     4.2       5    59.3    59.2\r\n",
            "   1991  12    8.3     1.7      12    12.0    60.7\r\n",
            "   1992   1    7.5     2.0      11    12.6    56.0\r\n",
            "   1992   2    9.5     2.3       8    17.7    50.3\r\n",
            "   1992   3   11.8     4.9       0    38.5    61.8\r\n",
            "   1992   4   14.0     5.6       1    57.1   129.7\r\n",
            "   1992   5   21.0    10.2       0    94.5   271.9\r\n",
            "   1992   6   22.5    12.3       0    22.5   213.7\r\n",
            "   1992   7   22.5    14.2       0    62.3   158.6\r\n",
            "   1992   8   21.7    13.6       0    84.7   149.2\r\n",
            "   1992   9   18.9    11.0       0    77.3   127.5\r\n",
            "   1992  10   12.5     5.3       3    59.4   112.6\r\n",
            "   1992  11   12.0     4.8       2    86.9    61.6\r\n",
            "   1992  12    7.8     1.6      12    35.9    49.1\r\n",
            "   1993   1   10.3     3.5       4    63.1    37.8\r\n",
            "   1993   2    7.2     2.5       2     2.4    51.0\r\n",
            "   1993   3   11.8     3.3       4    16.0   128.4\r\n",
            "   1993   4   14.6     6.8       0    75.3   126.9\r\n",
            "   1993   5   18.0     8.8       0    31.8   176.6\r\n",
            "   1993   6   21.8    12.2       0    43.9   224.2\r\n",
            "   1993   7   21.6    12.6       0    35.0   174.6\r\n",
            "   1993   8   21.6    11.7       0    23.8   219.4\r\n",
            "   1993   9   17.5     9.8       0    96.3   104.5\r\n",
            "   1993  10   13.0     7.0       1   123.0   117.0\r\n",
            "   1993  11    8.8     2.4      11    29.5    71.3\r\n",
            "   1993  12    9.2     3.6       3    73.8    52.4\r\n",
            "   1994   1    9.3     2.8       6    80.0    73.4\r\n",
            "   1994   2    7.7     1.2       8    42.6    72.0\r\n",
            "   1994   3   12.3     5.1       1    40.0   126.4\r\n",
            "   1994   4   13.3     5.1       1    52.8   175.0\r\n",
            "   1994   5   16.0     8.2       0    80.6   158.3\r\n",
            "   1994   6   21.5    11.2       0    17.0   265.0\r\n",
            "   1994   7   26.2    15.2       0    16.9   267.1\r\n",
            "   1994   8   23.0    13.8       0    32.2   180.9\r\n",
            "   1994   9   17.8    10.8       0    86.3   109.7\r\n",
            "   1994  10   15.4     7.7       0    76.0   141.0\r\n",
            "   1994  11   13.6     8.4       0    43.1    42.7\r\n",
            "   1994  12   10.7     4.0       6    63.3    60.8\r\n",
            "   1995   1    8.9     2.2       6   113.7    59.6\r\n",
            "   1995   2   10.7     4.4       1    71.9    70.9\r\n",
            "   1995   3   11.2     2.0       7    49.5   194.5\r\n",
            "   1995   4   15.0     6.1       3    16.9   199.5\r\n",
            "   1995   5   19.0     8.2       0    30.0   234.4\r\n",
            "   1995   6   20.7    10.8       0    11.1   187.7\r\n",
            "   1995   7   26.3    15.2       0    20.3   247.1\r\n",
            "   1995   8   27.0    15.6       0     0.3   295.3\r\n",
            "   1995   9   19.2    10.7       0    95.0   142.4\r\n",
            "   1995  10   18.3    10.2       0    19.2   129.9\r\n",
            "   1995  11   12.0     5.1       4    28.5    76.2\r\n",
            "   1995  12    5.8     1.0      13    82.8    44.7\r\n",
            "   1996   1    7.2     3.1       5    41.5    25.3\r\n",
            "   1996   2    6.8     0.1      17    49.0   100.3\r\n",
            "   1996   3    8.6     2.1       9    31.4    75.9\r\n",
            "   1996   4   14.3     5.5       3    25.0   147.5\r\n",
            "   1996   5   15.1     5.9       0    25.8   182.6\r\n",
            "   1996   6   22.8    11.3       0    12.0   282.7\r\n",
            "   1996   7   24.2    13.2       0    28.8   233.7\r\n",
            "   1996   8   23.1    13.4       0    45.8   217.6\r\n",
            "   1996   9   19.2    10.7       0    22.0   142.0\r\n",
            "   1996  10   16.6     8.9       0    35.4   142.3\r\n",
            "   1996  11   10.5     2.7       9    91.0   107.5\r\n",
            "   1996  12    6.2     1.4      11    13.0    57.6\r\n",
            "   1997   1    5.5     0.2      13    10.3    59.3\r\n",
            "   1997   2   10.8     4.0       4    55.1    58.1\r\n",
            "   1997   3   13.8     5.3       0    11.4   151.0\r\n",
            "   1997   4   15.6     5.4       1     9.8   218.5\r\n",
            "   1997   5   18.7     8.5       1    28.2   259.2\r\n",
            "   1997   6   20.2    12.2       0    78.6   151.6\r\n",
            "   1997   7   23.5    13.9       0    34.6   241.1\r\n",
            "   1997   8   25.8    16.6       0    70.5   194.2\r\n",
            "   1997   9   20.9    11.8       0     6.8   190.3\r\n",
            "   1997  10   15.9     7.5       3    44.9   166.0\r\n",
            "   1997  11   12.5     6.2       2    47.1    67.3\r\n",
            "   1997  12    9.5     4.2       4    47.4    48.0\r\n",
            "   1998   1    9.2     3.5       3    68.6    65.2\r\n",
            "   1998   2   11.6     3.5       5     6.6   113.1\r\n",
            "   1998   3   12.1     5.7       1    51.1    84.9\r\n",
            "   1998   4   12.7     5.7       0    82.6   115.4\r\n",
            "   1998   5   19.6    10.2       0    31.9   228.2\r\n",
            "   1998   6   19.9    12.0       0    89.6   158.4\r\n",
            "   1998   7   21.4    13.0       0    26.9   184.3\r\n",
            "   1998   8   23.5    12.7       0    16.6   262.6\r\n",
            "   1998   9   20.4    12.7       0   101.2   149.1\r\n",
            "   1998  10   14.7     8.6       0   103.8    96.7\r\n",
            "   1998  11    9.6     3.4       4    57.0    78.5\r\n",
            "   1998  12    9.7     3.8       7    49.2    42.4\r\n",
            "   1999   1    9.4     3.8       3    68.7    53.7\r\n",
            "   1999   2    8.8     2.8       7    21.1    90.1\r\n",
            "   1999   3   12.2     5.0       2    25.6   122.5\r\n",
            "   1999   4   14.9     6.3       1    35.0   167.8\r\n",
            "   1999   5   19.1    10.2       0    35.8   184.9\r\n",
            "   1999   6   20.3    11.0       0    98.2   239.1\r\n",
            "   1999   7   24.9    14.3       0     8.6   275.9\r\n",
            "   1999   8   22.8    14.0       0   124.8   199.8\r\n",
            "   1999   9   21.3    13.2       0    86.7   165.0\r\n",
            "   1999  10   15.6     7.9       0    49.2   160.5\r\n",
            "   1999  11   11.3     5.9       0    31.2    79.0\r\n",
            "   1999  12    8.7     2.4       7    77.2    75.3\r\n",
            "   2000   1    8.6     2.4       7    16.5    78.6\r\n",
            "   2000   2   10.4     3.8       5    62.2   102.5\r\n",
            "   2000   3   12.1     4.9       1    16.0   120.4\r\n",
            "   2000   4   12.9     5.4       0    99.6   135.8\r\n",
            "   2000   5   18.0     9.6       0    87.2   202.9\r\n",
            "   2000   6   21.0    12.8       0    19.2   169.5\r\n",
            "   2000   7   21.0    12.8       0    52.8   174.7\r\n",
            "   2000   8   23.2    14.0       0    32.3   211.4\r\n",
            "   2000   9   20.1    12.5       0   105.8   132.1\r\n",
            "   2000  10   14.7     8.5       0   155.4    98.0\r\n",
            "   2000  11   11.0     4.5       1    99.5    74.9\r\n",
            "   2000  12    9.0     4.6       5    73.9    50.0\r\n",
            "   2001   1    7.1     1.8       9    75.2    87.0\r\n",
            "   2001   2    9.2     2.8       5    69.6    92.3\r\n",
            "   2001   3    9.5     3.8       3    95.3    78.2\r\n",
            "   2001   4   12.8     5.4       0    66.5   138.5\r\n",
            "   2001   5   18.8     9.1       0    26.0   228.0\r\n",
            "   2001   6   20.8    11.3       0    39.1   248.0\r\n",
            "   2001   7   24.3    14.5       0    35.2   229.1\r\n",
            "   2001   8   23.5    14.5       0    79.0   210.9\r\n",
            "   2001   9   18.1    10.8       0    59.6   143.3\r\n",
            "   2001  10   17.6    11.3       0   108.2   109.9\r\n",
            "   2001  11   11.3     4.4       3    33.8    88.3\r\n",
            "   2001  12    7.3     1.4      11    17.8    93.3\r\n",
            "   2002   1    9.5     3.5       6    51.0    53.4\r\n",
            "   2002   2   11.3     4.8       2    64.0    91.4\r\n",
            "   2002   3   12.4     5.1       2    37.6   111.3\r\n",
            "   2002   4   15.7     6.1       0    38.4   220.5\r\n",
            "   2002   5   17.3     9.4       0    66.4   192.2\r\n",
            "   2002   6   20.1    11.6       0    74.2   191.5\r\n",
            "   2002   7   22.3    13.5       0    67.2   193.9\r\n",
            "   2002   8   23.3    14.7       0    36.3   190.4\r\n",
            "   2002   9   20.3    11.5       0    20.0   178.2\r\n",
            "   2002  10   15.3     8.4       0    61.6   109.2\r\n",
            "   2002  11   12.4     7.0       0   151.0    66.1\r\n",
            "   2002  12    9.0     5.2       0   119.0    34.1\r\n",
            "   2003   1    8.0     2.3      10    73.6    93.6\r\n",
            "   2003   2    8.4     1.8      10    20.8   101.2\r\n",
            "   2003   3   13.6     4.4       0    16.4   176.9\r\n",
            "   2003   4   15.7     6.3       3    30.0   198.0\r\n",
            "   2003   5   18.2     9.0       0    39.1   205.5\r\n",
            "   2003   6   23.3    13.3       0    47.6   245.5\r\n",
            "   2003   7   24.2    14.7       0    28.8   213.9\r\n",
            "   2003   8   26.4    15.7       0    10.4   255.3\r\n",
            "   2003   9   21.9    10.8       0     8.4   206.7\r\n",
            "   2003  10   14.5     6.4       0    35.2   160.7\r\n",
            "   2003  11   12.6     6.7       1   113.8    88.2\r\n",
            "   2003  12    8.8     3.2       3    51.4    58.0\r\n",
            "   2004   1    8.8     3.1       8    71.9    64.0\r\n",
            "   2004   2    8.7     3.8       7    26.2    65.3\r\n",
            "   2004   3   10.8     3.9       3    29.5   102.7\r\n",
            "   2004   4   14.9     6.3       0    68.8   155.0\r\n",
            "   2004   5   18.2     9.5       0    45.0   208.2\r\n",
            "   2004   6   22.1    12.6       0    40.4   236.0\r\n",
            "   2004   7   22.7    13.3       0    37.6   201.5\r\n",
            "   2004   8   23.8    15.1       0   107.8   213.3\r\n",
            "   2004   9   20.8    12.5       0    18.8   182.7\r\n",
            "   2004  10   15.3     9.1       0    96.6   101.2\r\n",
            "   2004  11   11.2     6.2       2    29.6    60.8\r\n",
            "   2004  12    8.8     2.9       5    46.4    48.2\r\n",
            "   2005   1    9.5     3.8       1    21.6    72.1\r\n",
            "   2005   2    7.3     2.5       7    19.7    62.4\r\n",
            "   2005   3   11.5     4.5       7    43.6    96.7\r\n",
            "   2005   4   14.6     6.2       1    30.0   153.0\r\n",
            "   2005   5   17.7     8.5       0    19.8   228.3\r\n",
            "   2005   6   22.8    12.9       0    32.6   219.3\r\n",
            "   2005   7   23.3    14.1       0    45.8   202.5\r\n",
            "   2005   8   23.2    13.0       0    42.4   250.4\r\n",
            "   2005   9   21.4    12.7       0    47.5   143.9#\r\n",
            "   2005  10   17.8    11.3       0    73.4    89.9#\r\n",
            "   2005  11   10.7     3.5       8    29.2    93.3#\r\n",
            "   2005  12    8.2     1.9       8    44.4    65.7#\r\n",
            "   2006   1    7.6     2.9       6    16.8    51.4#\r\n",
            "   2006   2    7.2     1.7       5    41.2    62.9#\r\n",
            "   2006   3    9.4     2.8      10    44.6    91.2#\r\n",
            "   2006   4   14.1     6.0       0    33.4   132.3#\r\n",
            "   2006   5   18.0     9.8       0    91.6   128.2#\r\n",
            "   2006   6   23.7    12.9       0    11.8   225.3#\r\n",
            "   2006   7   28.2    16.7       0    23.6   266.4#\r\n",
            "   2006   8   22.2    13.5       0    68.8   140.2#\r\n",
            "   2006   9   22.7    14.5       0    78.2   153.9#\r\n",
            "   2006  10   17.8    11.2       0    64.4   106.3#\r\n",
            "   2006  11   12.7     5.4       2    98.0    97.0#\r\n",
            "   2006  12    9.7     4.5       5    63.6    41.2#\r\n",
            "   2007   1   10.5     5.1       2    56.0    56.6#\r\n",
            "   2007   2    9.9     3.9       5    92.9    59.3#\r\n",
            "   2007   3   12.5     4.4       2    43.8   164.7#\r\n",
            "   2007   4   18.9     7.7       0     3.6   224.6#\r\n",
            "   2007   5   17.9     9.7       0    80.0   149.6#\r\n",
            "   2007   6   21.2    12.6       0    63.8   139.7#\r\n",
            "   2007   7   21.4    13.1       0   115.2   159.9#\r\n",
            "   2007   8   21.5    12.9       0    41.0   192.6#\r\n",
            "   2007   9   19.9    11.4       0    17.4   141.1#\r\n",
            "   2007  10   15.4     8.5       0    37.8    98.4#\r\n",
            "   2007  11   11.4     4.6       3    84.8    81.3#\r\n",
            "   2007  12    8.9     3.1       9    44.6    61.4#\r\n",
            "   2008   1   10.4     4.7       0    69.0    60.2#\r\n",
            "   2008   2   11.0     2.0       7    15.4   130.0#\r\n",
            "   2008   3   10.6     3.7       2    69.8    85.7#\r\n",
            "   2008   4   13.7     5.2       2    63.4   140.3#\r\n",
            "   2008   5   19.8    10.5       0    64.2   162.6#\r\n",
            "   2008   6   20.8    11.9       0    45.6   201.9#\r\n",
            "   2008   7   22.8    13.7       0    76.8   172.5#\r\n",
            "   2008   8   21.5    14.2       0    64.4   104.3#\r\n",
            "   2008   9   18.5    11.2       0    43.0   110.7#\r\n",
            "   2008  10   15.0     6.8       1    45.0   134.4#\r\n",
            "   2008  11   10.7     5.2       2    58.8    42.2#\r\n",
            "   2008  12    7.3     1.7      11    41.2    65.1#\r\n",
            "   2009   1    6.8     0.3      13    72.4    63.2#\r\n",
            "   2009   2    7.8     2.1      10    69.6    59.2#\r\n",
            "   2009   3   12.9     3.7       2    30.0   158.5#\r\n",
            "   2009   4   16.1     7.2       0    28.0   172.8#\r\n",
            "   2009   5   19.1     9.4       0    29.8   193.9#\r\n",
            "   2009   6   22.4    12.2       0    34.0   192.8#\r\n",
            "   2009   7   23.0    13.7       0    71.4   155.8#\r\n",
            "   2009   8   23.9    14.1       0    39.6   167.6#\r\n",
            "   2009   9   20.5    12.0       0    36.0   137.3#\r\n",
            "   2009  10   16.3     9.3       0    39.4    84.7#\r\n",
            "   2009  11   12.6     7.4       0   148.0    62.4#\r\n",
            "   2009  12    7.0     1.3      12    84.6    60.3#\r\n",
            "   2010   1    4.5    -0.3      15    51.8    51.3#\r\n",
            "   2010   2    6.9     1.7       8   100.4    46.7#\r\n",
            "   2010   3   11.1     3.7       4    39.8   106.4#\r\n",
            "   2010   4   15.8     5.6       0    23.2   201.7#\r\n",
            "   2010   5   17.3     7.7       0    20.6   170.4#\r\n",
            "   2010   6   23.5    12.1       0    12.4   220.1#\r\n",
            "   2010   7   25.0    15.1       0    18.0   161.8#\r\n",
            "   2010   8   21.6    13.2       0    88.6   110.9#\r\n",
            "   2010   9   19.4    11.2       0    38.2   128.7#\r\n",
            "   2010  10   15.2     8.3       1    74.8   104.0#\r\n",
            "   2010  11    9.1     4.0       7    32.2    50.0#\r\n",
            "   2010  12    3.9    -1.5      21    21.4    18.5#\r\n",
            "   2011   1    7.4     2.8       8    76.8    35.6#\r\n",
            "   2011   2   10.2     4.8       1    42.8    36.2#\r\n",
            "   2011   3   12.3     3.8       4    14.6   126.4#\r\n",
            "   2011   4   19.7     8.6       0     2.4   218.0#\r\n",
            "   2011   5   19.4     9.4       0    24.6   218.0#\r\n",
            "   2011   6   20.7    11.0       0    84.0   173.5#\r\n",
            "   2011   7   21.7    12.6       0    49.8   173.6#\r\n",
            "   2011   8   21.8    13.4       0    68.8   144.1#\r\n",
            "   2011   9   21.3    12.4       0    35.0   161.2#\r\n",
            "   2011  10   18.1    10.1       0    18.4   140.4#\r\n",
            "   2011  11   13.6     7.3       0    29.0    52.5#\r\n",
            "   2011  12    9.9     3.8       4    63.0    60.6#\r\n",
            "   2012   1    9.8     3.4       7    34.4    68.5#\r\n",
            "   2012   2    8.0     1.3      12    16.8    84.9#\r\n",
            "   2012   3   14.7     4.7       0    16.2   180.3#\r\n",
            "   2012   4   13.3     4.9       1    98.4   141.7#\r\n",
            "   2012   5   18.2     9.7       0    25.4   166.6#\r\n",
            "   2012   6   19.4    11.6       0   110.8   118.5#\r\n",
            "   2012   7   21.3    13.2       0    71.8   161.6#\r\n",
            "   2012   8   23.5    14.3       0    36.4   182.6#\r\n",
            "   2012   9   20.0    10.3       0    41.2   178.9#\r\n",
            "   2012  10   14.2     8.0       0    88.4    85.6#\r\n",
            "   2012  11   11.0     4.6       1    71.8    75.4#\r\n",
            "   2012  12    9.0     2.6      10    95.8    58.0#\r\n",
            "   2013   1    6.5     2.0      13    50.1    34.5#\r\n",
            "   2013   2    6.7     1.2       4    32.8    64.9#\r\n",
            "   2013   3    6.9     1.2      11    52.8    62.3#\r\n",
            "   2013   4   13.5     4.7       3    34.0   162.8#\r\n",
            "   2013   5   16.4     7.7       0    41.8   163.3#\r\n",
            "   2013   6   20.3    11.2       0    11.6   157.5#\r\n",
            "   2013   7   27.0    15.2       0    25.2   268.2#\r\n",
            "   2013   8   24.3    14.3       0    32.6   198.7#\r\n",
            "   2013   9   19.7    11.1       0    49.6   118.9#\r\n",
            "   2013  10   17.0    10.6       0    81.4    89.6#\r\n",
            "   2013  11   10.4     4.7       1    50.0    80.4#\r\n",
            "   2013  12   10.2     3.5       3    98.2    51.3#\r\n",
            "   2014   1   10.0     3.8       1   162.4    68.3#\r\n",
            "   2014   2   10.6     4.4       0    89.8    91.7#\r\n",
            "   2014   3   14.1     4.4       1    27.8   161.4#\r\n",
            "   2014   4   16.1     7.5       0    58.0   156.9#\r\n",
            "   2014   5   18.0     9.8       0    84.6   178.8#\r\n",
            "   2014   6   22.1    12.5       0    40.8   220.2#\r\n",
            "   2014   7   25.8    15.0       0    50.0   246.4#\r\n",
            "   2014   8   21.7    12.7       0    97.6   183.6#\r\n",
            "   2014   9   21.5    12.8       0    10.8   134.6#\r\n",
            "   2014  10   17.6    11.0       0    76.0   103.8#\r\n",
            "   2014  11   12.5     6.9       1   128.4    51.1#\r\n",
            "   2014  12    9.2     3.0       7    37.8    71.6#\r\n",
            "   2015   1    8.8     1.6      10    63.4    62.0#\r\n",
            "   2015   2    8.0     1.8       8    38.6    63.9#\r\n",
            "   2015   3   11.6     4.1       1    24.0   140.7#\r\n",
            "   2015   4   16.3     6.0       0    16.2   212.1#\r\n",
            "   2015   5   17.6     8.8       0    41.6   189.0#\r\n",
            "   2015   6   22.2    11.4       0    12.2   197.0#\r\n",
            "   2015   7   23.7    13.8       0    71.8   189.7#\r\n",
            "   2015   8   22.2    14.1       0   116.8   134.1#\r\n",
            "   2015   9   18.6    10.2       0    50.0   162.3#\r\n",
            "   2015  10   15.8     9.3       0    39.8    94.2#\r\n",
            "   2015  11   13.4     8.0       2    48.2    27.7#\r\n",
            "   2015  12   13.7     8.9       0    39.4    35.0#\r\n",
            "   2016   1    9.5     3.0       5    74.8    54.8#\r\n",
            "   2016   2    9.4     2.9       5    43.8    86.8#\r\n",
            "   2016   3   10.7     3.2       3    72.8   123.3#\r\n",
            "   2016   4   13.5     4.9       0    47.2   170.0#\r\n",
            "   2016   5   19.0     9.7       0    60.4   192.7#\r\n",
            "   2016   6   20.7    12.7       0    93.4   101.7#\r\n",
            "   2016   7   24.0    14.5       0    16.0   182.8#\r\n",
            "   2016   8   24.7    14.6       0    21.6   201.4#\r\n",
            "   2016   9   22.4    13.7       0    42.2   122.1#\r\n",
            "   2016  10   15.9     8.7       0    21.6   105.6#\r\n",
            "   2016  11   10.5     3.8       3    86.4    77.4#\r\n",
            "   2016  12   10.2     3.4       7    10.4    55.1#\r\n",
            "   2017   1    7.6     0.7      15    60.2    64.5#\r\n",
            "   2017   2   10.0     4.4       1    38.2    47.8#\r\n",
            "   2017   3   14.1     6.6       0    25.8   116.3#\r\n",
            "   2017   4   15.8     5.9       0     4.6   186.2#\r\n",
            "   2017   5   19.8    10.4       0    64.8   164.8#\r\n",
            "   2017   6   24.0    13.9       0    46.4   204.3#\r\n",
            "   2017   7   23.8    14.9       0    90.0   178.0#\r\n",
            "   2017   8   22.0    13.5       0    58.6   174.9#\r\n",
            "   2017   9   19.2    11.0       0    59.0   120.1#\r\n",
            "   2017  10   17.1    10.3       0     9.2    84.6#\r\n",
            "   2017  11   11.1     4.5       2    34.2    66.7#\r\n",
            "   2017  12    8.7     2.9       7    81.2    43.8#\r\n",
            "   2018   1    9.7     3.8       1    58.0    46.5#\r\n",
            "   2018   2    6.7     0.6      12    29.0    92.0#\r\n",
            "   2018   3    9.8     3.0       6    81.2    70.3#\r\n",
            "   2018   4   15.5     7.9       0    65.2   113.4#\r\n",
            "   2018   5   20.8     9.8       0    58.4   248.3#\r\n",
            "   2018   6   24.2    13.1       0     0.4   234.5#\r\n",
            "   2018   7   28.3    16.4       0    14.8   272.5#\r\n",
            "   2018   8   24.5    14.5       0    48.2   182.1#\r\n",
            "   2018   9   20.9    11.0       0    29.4   195.0#\r\n",
            "   2018  10   16.5     8.5       1    61.0   137.0#\r\n",
            "   2018  11   12.2     5.8       1    73.8    72.9#\r\n",
            "   2018  12   10.7     5.2       2    60.6    40.3#\r\n",
            "   2019   1    7.6     2.0       9    33.2    56.4#\r\n",
            "   2019   2   12.4     3.3       3    34.2   120.2#\r\n",
            "   2019   3   13.1     5.8       0    49.6   119.0#\r\n",
            "   2019   4   15.8     5.7       1    12.8   170.1#\r\n",
            "   2019   5   18.6     8.4       0    36.0   176.3#\r\n",
            "   2019   6   21.8    11.9       0    81.8   170.1#\r\n",
            "   2019   7   25.5    14.9       0    50.8   194.5#\r\n",
            "   2019   8   25.2    14.1       0    33.6   201.2#\r\n",
            "   2019   9   21.2    11.8       0    63.0   156.8#\r\n",
            "   2019  10   15.5     8.6       0    92.8    74.0#\r\n",
            "   2019  11   10.3     4.3       3    74.8    51.3#\r\n",
            "   2019  12   10.2     4.0       3    89.6    56.2#\r\n",
            "   2020   1   10.1     4.7       4    47.6    50.3#\r\n",
            "   2020   2   11.1     4.3       1    99.8    62.0#\r\n",
            "   2020   3   12.0     3.9       1    42.8   148.0#\r\n",
            "   2020   4   18.2     6.5       1    38.2   235.4#\r\n",
            "   2020   5   21.1     9.1       0     2.0   308.6#\r\n",
            "   2020   6   22.5    12.6       0    54.0   174.9#\r\n",
            "   2020   7   23.8    13.4       0    35.2   171.2#\r\n",
            "   2020   8   25.6    15.6       0    58.2   161.8#\r\n",
            "   2020   9   21.6    11.2       0    20.0   168.9#\r\n",
            "   2020  10   15.1     8.8       0   142.2    51.6#\r\n",
            "   2020  11   12.7     6.2       2    50.2    44.6#\r\n",
            "   2020  12    8.5     3.5       7    72.4    36.5#\r\n",
            "   2021   1    7.0     1.3      12    96.6    29.4#\r\n",
            "   2021   2    9.1     3.1       7    36.4    57.9#\r\n",
            "   2021   3   12.1     4.1       1    24.6    91.4#\r\n",
            "   2021   4   13.1     2.9       5     7.2   202.6#\r\n",
            "   2021   5   16.5     7.2       0    84.6   131.9#\r\n",
            "   2021   6   22.5    13.3       0    88.2   159.6#\r\n",
            "   2021   7   24.2    14.9       0    61.2   171.1#\r\n",
            "   2021   8   21.9    13.4       0    42.2    95.6#\r\n",
            "   2021   9   22.3    13.3       0    52.4   124.0#\r\n",
            "   2021  10   16.9     9.7       0    87.6    84.2#\r\n",
            "   2021  11   11.4     4.5       3    10.2    67.8#\r\n",
            "   2021  12   10.1     5.3       3    71.2    21.1#\r\n",
            "   2022   1    8.9     1.9       9    17.2    67.1#\r\n",
            "   2022   2   11.3     4.0       3    49.6    78.4#\r\n",
            "   2022   3   13.2     4.9       1    31.4   157.2#\r\n",
            "   2022   4   16.1     5.7       1    16.4   167.2#\r\n",
            "   2022   5   20.2    10.1       0    34.2   155.3#\r\n",
            "   2022   6   23.2    11.9       0    24.0   212.2#\r\n",
            "   2022   7   27.2    15.5       0     7.6   221.1#\r\n",
            "   2022   8   27.0    15.9       0    54.4   234.3#\r\n",
            "   2022   9   20.2    11.8       0    86.0   119.1#\r\n",
            "   2022  10   18.3    10.4       0    81.4   132.8#\r\n",
            "   2022  11   13.2     7.6       0   123.8    69.9#\r\n",
            "   2022  12    7.9     1.7      11    51.6    56.4#\r\n",
            "   2023   1    9.0     2.5      10    59.0    68.2#\r\n",
            "   2023   2   10.8     3.4       6     4.2    81.3#\r\n",
            "   2023   3   11.5     5.2       1    92.4    60.2#\r\n",
            "   2023   4   14.6     5.9       0    65.8   151.1#\r\n",
            "   2023   5   18.6     9.3       0    38.4   196.6#\r\n",
            "   2023   6   25.3    13.5       0    56.8   250.2#\r\n",
            "   2023   7   22.9    14.0       0    61.4   150.1#\r\n",
            "   2023   8   23.0    13.8       0    53.0   171.1#\r\n",
            "   2023   9   24.4    14.7       0    59.4   167.9#\r\n",
            "   2023  10   18.1    10.2       0   116.8   112.9#\r\n",
            "   2023  11   11.8     5.4       3    78.4    74.9#\r\n",
            "   2023  12   10.9     5.9       3    76.4    21.0#\r\n",
            "   2024   1    8.4     2.5       8    50.6    71.4#  Provisional\r\n",
            "   2024   2   12.2     6.0       2   100.4    48.6#  Provisional\r\n",
            "   2024   3   13.1     5.9       0    85.0    94.9#  Provisional\r\n",
            "   2024   4   15.0     7.2       0    68.6   126.3#  Provisional\r\n",
            "   2024   5   19.6    10.6       0    54.4   164.2#  Provisional\r\n",
            "   2024   6   22.0    11.1       0    12.4   205.7#  Provisional\r\n",
            "   2024   7   23.5    13.8       0    83.6   178.2#  Provisional\r\n",
            "   2024   8   24.5    14.6       0    28.4   188.6#  Provisional\r\n",
            "   2024   9   20.1    11.9       0   114.8   121.9#  Provisional\r\n",
            "   2024  10   16.4     9.4       0    57.2    80.6#  Provisional\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "### Try This: Retrieving A file\n",
        "If you're working with the data file above and want to break each line into separate fields, how might you do that? What other processing would you expect to do? Try writing some code to retrieve this file and calculate the average annual rainfall or, for more of a challenge, the average maximum and minimum temperature for each year.\n"
      ],
      "metadata": {
        "id": "QW9xVuS0ckY_"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# @title\n",
        "import requests\n",
        "response = requests.get(\"http://www.metoffice.gov.uk/pub/data/weather/uk/climate/stationdata/heathrowdata.txt\")\n",
        "\n",
        "data = response.text\n",
        "data_rows = []\n",
        "rainfall = []\n",
        "for row in data.split(\"\\r\\n\")[7:]:\n",
        "    fields = [x for x in row.split(\" \") if x]\n",
        "    data_rows.append(fields)\n",
        "    rainfall.append(float(fields[5]))\n",
        "\n",
        "print(\"Average rainfall = {} mm\".format(sum(rainfall)/len(rainfall)))\n"
      ],
      "metadata": {
        "cellView": "form",
        "id": "ZrpnFo8xdZmT"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "#22.2 Fetching data via an API"
      ],
      "metadata": {
        "id": "-Yvrjojmcv2l"
      }
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Ifakq0Rck0jn",
        "outputId": "bd0714a1-1355-4b68-ed83-9fc6250c64c0",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 70
        }
      },
      "source": [
        "response = requests.get(\"https://api.open-meteo.com/v1/forecast?latitude=41.882&longitude=-87.623&current=temperature_2m,wind_speed_10m\")\n",
        "weather = response.text\n",
        "weather"
      ],
      "execution_count": 50,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "'{\"latitude\":41.879482,\"longitude\":-87.64975,\"generationtime_ms\":0.03910064697265625,\"utc_offset_seconds\":0,\"timezone\":\"GMT\",\"timezone_abbreviation\":\"GMT\",\"elevation\":185.0,\"current_units\":{\"time\":\"iso8601\",\"interval\":\"seconds\",\"temperature_2m\":\"°C\",\"wind_speed_10m\":\"km/h\"},\"current\":{\"time\":\"2024-11-28T02:15\",\"interval\":900,\"temperature_2m\":1.0,\"wind_speed_10m\":9.2}}'"
            ],
            "application/vnd.google.colaboratory.intrinsic+json": {
              "type": "string"
            }
          },
          "metadata": {},
          "execution_count": 50
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "result = requests.get(\"https://data.cityofchicago.org/resource/6zsd-86xi.json?$where=date between '2024-01-10T12:01:00' and '2024-01-10T12:10:00'\")\n",
        "result.json()"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "5E7GD4eMFPBl",
        "outputId": "9155d0cd-94df-4ed5-cd4c-d90024468700"
      },
      "execution_count": 51,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "[{'id': '13334404',\n",
              "  'case_number': 'JH111115',\n",
              "  'date': '2024-01-10T12:01:00.000',\n",
              "  'block': '009XX W WINONA ST',\n",
              "  'iucr': '2020',\n",
              "  'primary_type': 'NARCOTICS',\n",
              "  'description': 'POSSESS - AMPHETAMINES',\n",
              "  'location_description': 'APARTMENT',\n",
              "  'arrest': True,\n",
              "  'domestic': False,\n",
              "  'beat': '2024',\n",
              "  'district': '020',\n",
              "  'ward': '48',\n",
              "  'community_area': '3',\n",
              "  'fbi_code': '18',\n",
              "  'x_coordinate': '1169132',\n",
              "  'y_coordinate': '1934325',\n",
              "  'year': '2024',\n",
              "  'updated_on': '2024-01-18T15:41:44.000',\n",
              "  'latitude': '41.975305734',\n",
              "  'longitude': '-87.653416364',\n",
              "  'location': {'type': 'Point', 'coordinates': [-87.653416364, 41.975305734]},\n",
              "  'location_address': '',\n",
              "  'location_city': '',\n",
              "  'location_state': '',\n",
              "  'location_zip': ''},\n",
              " {'id': '13334420',\n",
              "  'case_number': 'JH111020',\n",
              "  'date': '2024-01-10T12:01:00.000',\n",
              "  'block': '009XX W WINONA ST',\n",
              "  'iucr': '1330',\n",
              "  'primary_type': 'CRIMINAL TRESPASS',\n",
              "  'description': 'TO LAND',\n",
              "  'location_description': 'APARTMENT',\n",
              "  'arrest': True,\n",
              "  'domestic': False,\n",
              "  'beat': '2024',\n",
              "  'district': '020',\n",
              "  'ward': '48',\n",
              "  'community_area': '3',\n",
              "  'fbi_code': '26',\n",
              "  'x_coordinate': '1169132',\n",
              "  'y_coordinate': '1934325',\n",
              "  'year': '2024',\n",
              "  'updated_on': '2024-01-18T15:41:44.000',\n",
              "  'latitude': '41.975305734',\n",
              "  'longitude': '-87.653416364',\n",
              "  'location': {'type': 'Point', 'coordinates': [-87.653416364, 41.975305734]},\n",
              "  'location_address': '',\n",
              "  'location_city': '',\n",
              "  'location_state': '',\n",
              "  'location_zip': ''},\n",
              " {'id': '13335828',\n",
              "  'case_number': 'JH112908',\n",
              "  'date': '2024-01-10T12:07:00.000',\n",
              "  'block': '012XX W 97TH ST',\n",
              "  'iucr': '0820',\n",
              "  'primary_type': 'THEFT',\n",
              "  'description': '$500 AND UNDER',\n",
              "  'location_description': 'RESIDENCE - PORCH / HALLWAY',\n",
              "  'arrest': True,\n",
              "  'domestic': False,\n",
              "  'beat': '2213',\n",
              "  'district': '022',\n",
              "  'ward': '21',\n",
              "  'community_area': '73',\n",
              "  'fbi_code': '06',\n",
              "  'x_coordinate': '1169758',\n",
              "  'y_coordinate': '1840605',\n",
              "  'year': '2024',\n",
              "  'updated_on': '2024-05-16T15:40:03.000',\n",
              "  'latitude': '41.718116179',\n",
              "  'longitude': '-87.653841221',\n",
              "  'location': {'type': 'Point', 'coordinates': [-87.653841221, 41.718116179]},\n",
              "  'location_address': '',\n",
              "  'location_city': '',\n",
              "  'location_state': '',\n",
              "  'location_zip': ''},\n",
              " {'id': '13334431',\n",
              "  'case_number': 'JH111022',\n",
              "  'date': '2024-01-10T12:07:00.000',\n",
              "  'block': '044XX N BROADWAY',\n",
              "  'iucr': '0860',\n",
              "  'primary_type': 'THEFT',\n",
              "  'description': 'RETAIL THEFT',\n",
              "  'location_description': 'DEPARTMENT STORE',\n",
              "  'arrest': False,\n",
              "  'domestic': False,\n",
              "  'beat': '1913',\n",
              "  'district': '019',\n",
              "  'ward': '46',\n",
              "  'community_area': '3',\n",
              "  'fbi_code': '06',\n",
              "  'x_coordinate': '1168469',\n",
              "  'y_coordinate': '1929861',\n",
              "  'year': '2024',\n",
              "  'updated_on': '2024-01-18T15:41:44.000',\n",
              "  'latitude': '41.963070794',\n",
              "  'longitude': '-87.655984213',\n",
              "  'location': {'type': 'Point', 'coordinates': [-87.655984213, 41.963070794]},\n",
              "  'location_address': '',\n",
              "  'location_city': '',\n",
              "  'location_state': '',\n",
              "  'location_zip': ''},\n",
              " {'id': '13334379',\n",
              "  'case_number': 'JH111007',\n",
              "  'date': '2024-01-10T12:07:00.000',\n",
              "  'block': '039XX S WELLS ST',\n",
              "  'iucr': '143A',\n",
              "  'primary_type': 'WEAPONS VIOLATION',\n",
              "  'description': 'UNLAWFUL POSSESSION - HANDGUN',\n",
              "  'location_description': 'STREET',\n",
              "  'arrest': True,\n",
              "  'domestic': False,\n",
              "  'beat': '0925',\n",
              "  'district': '009',\n",
              "  'ward': '3',\n",
              "  'community_area': '37',\n",
              "  'fbi_code': '15',\n",
              "  'x_coordinate': '1175263',\n",
              "  'y_coordinate': '1878937',\n",
              "  'year': '2024',\n",
              "  'updated_on': '2024-01-18T15:41:44.000',\n",
              "  'latitude': '41.823182522',\n",
              "  'longitude': '-87.632534564',\n",
              "  'location': {'type': 'Point', 'coordinates': [-87.632534564, 41.823182522]},\n",
              "  'location_address': '',\n",
              "  'location_city': '',\n",
              "  'location_state': '',\n",
              "  'location_zip': ''},\n",
              " {'id': '13334587',\n",
              "  'case_number': 'JH111272',\n",
              "  'date': '2024-01-10T12:08:00.000',\n",
              "  'block': '008XX W SHERIDAN RD',\n",
              "  'iucr': '1540',\n",
              "  'primary_type': 'OBSCENITY',\n",
              "  'description': 'OBSCENE MATTER',\n",
              "  'location_description': 'SCHOOL - PUBLIC BUILDING',\n",
              "  'arrest': True,\n",
              "  'domestic': False,\n",
              "  'beat': '1923',\n",
              "  'district': '019',\n",
              "  'ward': '46',\n",
              "  'community_area': '6',\n",
              "  'fbi_code': '26',\n",
              "  'x_coordinate': '1169949',\n",
              "  'y_coordinate': '1926105',\n",
              "  'year': '2024',\n",
              "  'updated_on': '2024-01-18T15:41:44.000',\n",
              "  'latitude': '41.952731972',\n",
              "  'longitude': '-87.650652832',\n",
              "  'location': {'type': 'Point', 'coordinates': [-87.650652832, 41.952731972]},\n",
              "  'location_address': '',\n",
              "  'location_city': '',\n",
              "  'location_state': '',\n",
              "  'location_zip': ''}]"
            ]
          },
          "metadata": {},
          "execution_count": 51
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "result.url"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        },
        "id": "rPECylR6VcPS",
        "outputId": "30cf1150-1feb-4f5a-b3e8-21f1a057c06e"
      },
      "execution_count": 52,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "\"https://data.cityofchicago.org/resource/6zsd-86xi.json?$where=date%20between%20'2024-01-10T12:01:00'%20and%20'2024-01-10T12:10:00'\""
            ],
            "application/vnd.google.colaboratory.intrinsic+json": {
              "type": "string"
            }
          },
          "metadata": {},
          "execution_count": 52
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "### Try This: Accessing an API\n",
        "Write some code to fetch some data from the city of Chicago website. Look at the fields mentioned in the results, and see whether you can select records based on another field in combination with the date range."
      ],
      "metadata": {
        "id": "0ZUWIKlUdF1b"
      }
    },
    {
      "cell_type": "code",
      "source": [],
      "metadata": {
        "id": "HlO8sT8WdMFi"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# @title\n",
        "import requests\n",
        "response = requests.get(\"https://data.cityofchicago.org/resource/6zsd-86xi.json?$where=date between '2015-01-10T12:00:00' and '2015-01-10T13:00:00'&arrest=true\")\n",
        "\n",
        "print(response.text)"
      ],
      "metadata": {
        "cellView": "form",
        "id": "lvv1RB_udMNY"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "22.3.1 JSON data"
      ],
      "metadata": {
        "id": "GMRK5A9IdzMu"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "import json\n",
        "import requests\n",
        "response = requests.get(\"https://api.open-meteo.com/v1/forecast?latitude=41.882&longitude=-87.623&current=temperature_2m,wind_speed_10m\")\n",
        "weather = json.loads(response.text)\n",
        "weather"
      ],
      "metadata": {
        "id": "ObgkmQG3h8tR",
        "outputId": "650bf3dc-1240-4939-9a2e-36737b98dc42",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "execution_count": 9,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "{'latitude': 41.879482,\n",
              " 'longitude': -87.64975,\n",
              " 'generationtime_ms': 0.01895427703857422,\n",
              " 'utc_offset_seconds': 0,\n",
              " 'timezone': 'GMT',\n",
              " 'timezone_abbreviation': 'GMT',\n",
              " 'elevation': 185.0,\n",
              " 'current_units': {'time': 'iso8601',\n",
              "  'interval': 'seconds',\n",
              "  'temperature_2m': '°C',\n",
              "  'wind_speed_10m': 'km/h'},\n",
              " 'current': {'time': '2024-11-28T01:45',\n",
              "  'interval': 900,\n",
              "  'temperature_2m': 1.1,\n",
              "  'wind_speed_10m': 8.7}}"
            ]
          },
          "metadata": {},
          "execution_count": 9
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "weather[\"current\"][\"temperature_2m\"]"
      ],
      "metadata": {
        "id": "m3qWFKCMifaf",
        "outputId": "340b49ea-15a5-42dd-91aa-9f93c833f1c7",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "execution_count": 10,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "1.1"
            ]
          },
          "metadata": {},
          "execution_count": 10
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "from pprint import pprint as pp\n",
        "pp(weather)"
      ],
      "metadata": {
        "id": "-d2g3TI0ioRs",
        "outputId": "e99d05c3-7e71-479d-cdb3-ee00f00224bb",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "execution_count": 11,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "{'current': {'interval': 900,\n",
            "             'temperature_2m': 1.1,\n",
            "             'time': '2024-11-28T01:45',\n",
            "             'wind_speed_10m': 8.7},\n",
            " 'current_units': {'interval': 'seconds',\n",
            "                   'temperature_2m': '°C',\n",
            "                   'time': 'iso8601',\n",
            "                   'wind_speed_10m': 'km/h'},\n",
            " 'elevation': 185.0,\n",
            " 'generationtime_ms': 0.01895427703857422,\n",
            " 'latitude': 41.879482,\n",
            " 'longitude': -87.64975,\n",
            " 'timezone': 'GMT',\n",
            " 'timezone_abbreviation': 'GMT',\n",
            " 'utc_offset_seconds': 0}\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ZrRpTK7ik0jq",
        "outputId": "1f87ff16-da7e-48a8-f0e6-af01dd09d53a",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 70
        }
      },
      "source": [
        "import json\n",
        "outfile = open(\"weather_01.json\", \"w\")\n",
        "json.dump(weather, outfile)\n",
        "outfile.close()\n",
        "json.dumps(weather)"
      ],
      "execution_count": 12,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "'{\"latitude\": 41.879482, \"longitude\": -87.64975, \"generationtime_ms\": 0.01895427703857422, \"utc_offset_seconds\": 0, \"timezone\": \"GMT\", \"timezone_abbreviation\": \"GMT\", \"elevation\": 185.0, \"current_units\": {\"time\": \"iso8601\", \"interval\": \"seconds\", \"temperature_2m\": \"\\\\u00b0C\", \"wind_speed_10m\": \"km/h\"}, \"current\": {\"time\": \"2024-11-28T01:45\", \"interval\": 900, \"temperature_2m\": 1.1, \"wind_speed_10m\": 8.7}}'"
            ],
            "application/vnd.google.colaboratory.intrinsic+json": {
              "type": "string"
            }
          },
          "metadata": {},
          "execution_count": 12
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "2xqSiLyEk0jr",
        "outputId": "605b7dcf-c6db-4800-ef85-9ea967e74d46",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "source": [
        "print(json.dumps(weather, indent=2))"
      ],
      "execution_count": 13,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "{\n",
            "  \"latitude\": 41.879482,\n",
            "  \"longitude\": -87.64975,\n",
            "  \"generationtime_ms\": 0.01895427703857422,\n",
            "  \"utc_offset_seconds\": 0,\n",
            "  \"timezone\": \"GMT\",\n",
            "  \"timezone_abbreviation\": \"GMT\",\n",
            "  \"elevation\": 185.0,\n",
            "  \"current_units\": {\n",
            "    \"time\": \"iso8601\",\n",
            "    \"interval\": \"seconds\",\n",
            "    \"temperature_2m\": \"\\u00b0C\",\n",
            "    \"wind_speed_10m\": \"km/h\"\n",
            "  },\n",
            "  \"current\": {\n",
            "    \"time\": \"2024-11-28T01:45\",\n",
            "    \"interval\": 900,\n",
            "    \"temperature_2m\": 1.1,\n",
            "    \"wind_speed_10m\": 8.7\n",
            "  }\n",
            "}\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "weather_list = [weather]\n",
        "response = requests.get(\"https://api.open-meteo.com/v1/forecast?latitude=38.624&longitude=-90.195&current=temperature_2m,wind_speed_10m\")\n",
        "\n",
        "weather_list.append(response.json())\n",
        "\n",
        "weather_list"
      ],
      "metadata": {
        "id": "E2fuU0arlwU4",
        "outputId": "f66737e9-6962-4cd2-df1f-434a08725c03",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "execution_count": 14,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "[{'latitude': 41.879482,\n",
              "  'longitude': -87.64975,\n",
              "  'generationtime_ms': 0.01895427703857422,\n",
              "  'utc_offset_seconds': 0,\n",
              "  'timezone': 'GMT',\n",
              "  'timezone_abbreviation': 'GMT',\n",
              "  'elevation': 185.0,\n",
              "  'current_units': {'time': 'iso8601',\n",
              "   'interval': 'seconds',\n",
              "   'temperature_2m': '°C',\n",
              "   'wind_speed_10m': 'km/h'},\n",
              "  'current': {'time': '2024-11-28T01:45',\n",
              "   'interval': 900,\n",
              "   'temperature_2m': 1.1,\n",
              "   'wind_speed_10m': 8.7}},\n",
              " {'latitude': 38.62057,\n",
              "  'longitude': -90.17848,\n",
              "  'generationtime_ms': 0.20599365234375,\n",
              "  'utc_offset_seconds': 0,\n",
              "  'timezone': 'GMT',\n",
              "  'timezone_abbreviation': 'GMT',\n",
              "  'elevation': 137.0,\n",
              "  'current_units': {'time': 'iso8601',\n",
              "   'interval': 'seconds',\n",
              "   'temperature_2m': '°C',\n",
              "   'wind_speed_10m': 'km/h'},\n",
              "  'current': {'time': '2024-11-28T01:45',\n",
              "   'interval': 900,\n",
              "   'temperature_2m': 4.6,\n",
              "   'wind_speed_10m': 11.3}}]"
            ]
          },
          "metadata": {},
          "execution_count": 14
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "T4bSzCn-k0jr"
      },
      "source": [
        "outfile = open(\"weather_list.json\", \"w\")\n",
        "for report in weather_list:\n",
        "    outfile.write(json.dumps(report) + \"\\n\")\n",
        "outfile.close()\n"
      ],
      "execution_count": 16,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "print(open(\"weather_list.json\", \"r\").read())"
      ],
      "metadata": {
        "id": "ZGZvU_Q8mw_A",
        "outputId": "f0084257-dd63-42bf-fa3f-65432a68fe9e",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "{\"latitude\": 41.879482, \"longitude\": -87.64975, \"generationtime_ms\": 0.025987625122070312, \"utc_offset_seconds\": 0, \"timezone\": \"GMT\", \"timezone_abbreviation\": \"GMT\", \"elevation\": 185.0, \"current_units\": {\"time\": \"iso8601\", \"interval\": \"seconds\", \"temperature_2m\": \"\\u00b0C\", \"wind_speed_10m\": \"km/h\"}, \"current\": {\"time\": \"2024-09-02T02:15\", \"interval\": 900, \"temperature_2m\": 16.9, \"wind_speed_10m\": 13.8}}\n",
            "{\"latitude\": 38.62057, \"longitude\": -90.17848, \"generationtime_ms\": 0.024080276489257812, \"utc_offset_seconds\": 0, \"timezone\": \"GMT\", \"timezone_abbreviation\": \"GMT\", \"elevation\": 137.0, \"current_units\": {\"time\": \"iso8601\", \"interval\": \"seconds\", \"temperature_2m\": \"\\u00b0C\", \"wind_speed_10m\": \"km/h\"}, \"current\": {\"time\": \"2024-09-02T02:45\", \"interval\": 900, \"temperature_2m\": 23.9, \"wind_speed_10m\": 15.1}}\n",
            "\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "oLDGsXMHk0jr",
        "outputId": "d375c1f7-d688-42c3-a6de-017f7128d1cb",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "source": [
        "weather_list2 = []\n",
        "for line in open(\"weather_list.json\"):\n",
        "    weather_list2.append(json.loads(line))\n",
        "weather_list2"
      ],
      "execution_count": 17,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "[{'latitude': 41.879482,\n",
              "  'longitude': -87.64975,\n",
              "  'generationtime_ms': 0.01895427703857422,\n",
              "  'utc_offset_seconds': 0,\n",
              "  'timezone': 'GMT',\n",
              "  'timezone_abbreviation': 'GMT',\n",
              "  'elevation': 185.0,\n",
              "  'current_units': {'time': 'iso8601',\n",
              "   'interval': 'seconds',\n",
              "   'temperature_2m': '°C',\n",
              "   'wind_speed_10m': 'km/h'},\n",
              "  'current': {'time': '2024-11-28T01:45',\n",
              "   'interval': 900,\n",
              "   'temperature_2m': 1.1,\n",
              "   'wind_speed_10m': 8.7}},\n",
              " {'latitude': 38.62057,\n",
              "  'longitude': -90.17848,\n",
              "  'generationtime_ms': 0.20599365234375,\n",
              "  'utc_offset_seconds': 0,\n",
              "  'timezone': 'GMT',\n",
              "  'timezone_abbreviation': 'GMT',\n",
              "  'elevation': 137.0,\n",
              "  'current_units': {'time': 'iso8601',\n",
              "   'interval': 'seconds',\n",
              "   'temperature_2m': '°C',\n",
              "   'wind_speed_10m': 'km/h'},\n",
              "  'current': {'time': '2024-11-28T01:45',\n",
              "   'interval': 900,\n",
              "   'temperature_2m': 4.6,\n",
              "   'wind_speed_10m': 11.3}}]"
            ]
          },
          "metadata": {},
          "execution_count": 17
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "e3GdwTYyk0js"
      },
      "source": [
        "outfile = open(\"weather_obj.json\", \"w\")\n",
        "weather_obj = {\"reports\": weather_list, \"count\": 2}\n",
        "json.dump(weather_obj, outfile)\n",
        "outfile.close()"
      ],
      "execution_count": 18,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "oJY_JSF0k0js",
        "outputId": "f4b252dd-5775-4e07-d714-7b0c8de59cb0",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "source": [
        "with open(\"weather_obj.json\") as infile:\n",
        "    weather_obj = json.load(infile)\n",
        "weather_obj"
      ],
      "execution_count": 19,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "{'reports': [{'latitude': 41.879482,\n",
              "   'longitude': -87.64975,\n",
              "   'generationtime_ms': 0.01895427703857422,\n",
              "   'utc_offset_seconds': 0,\n",
              "   'timezone': 'GMT',\n",
              "   'timezone_abbreviation': 'GMT',\n",
              "   'elevation': 185.0,\n",
              "   'current_units': {'time': 'iso8601',\n",
              "    'interval': 'seconds',\n",
              "    'temperature_2m': '°C',\n",
              "    'wind_speed_10m': 'km/h'},\n",
              "   'current': {'time': '2024-11-28T01:45',\n",
              "    'interval': 900,\n",
              "    'temperature_2m': 1.1,\n",
              "    'wind_speed_10m': 8.7}},\n",
              "  {'latitude': 38.62057,\n",
              "   'longitude': -90.17848,\n",
              "   'generationtime_ms': 0.20599365234375,\n",
              "   'utc_offset_seconds': 0,\n",
              "   'timezone': 'GMT',\n",
              "   'timezone_abbreviation': 'GMT',\n",
              "   'elevation': 137.0,\n",
              "   'current_units': {'time': 'iso8601',\n",
              "    'interval': 'seconds',\n",
              "    'temperature_2m': '°C',\n",
              "    'wind_speed_10m': 'km/h'},\n",
              "   'current': {'time': '2024-11-28T01:45',\n",
              "    'interval': 900,\n",
              "    'temperature_2m': 4.6,\n",
              "    'wind_speed_10m': 11.3}}],\n",
              " 'count': 2}"
            ]
          },
          "metadata": {},
          "execution_count": 19
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "### Try this: Saving some JSON crime data\n",
        "Modify the code you wrote in section 22.2 to fetch the Chicago crime data. Then convert the fetched data from a JSON-formatted string to a Python object. Next, see whether you can save the crime events as a series of separate JSON strings in one file and as one JSON object in another file. Then see what code is needed to load each file."
      ],
      "metadata": {
        "id": "XAwCtpRJetij"
      }
    },
    {
      "cell_type": "code",
      "source": [],
      "metadata": {
        "id": "wOubV_05e0ze"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# @title\n",
        "import json\n",
        "import requests\n",
        "\n",
        "response = requests.get(\"https://data.cityofchicago.org/resource/6zsd-86xi.json?$where=date between '2015-01-10T12:00:00' and '2015-01-10T13:00:00'&arrest=true\")\n",
        "\n",
        "crime_data = json.loads(response.text)\n",
        "\n",
        "with open(\"crime_all.json\", \"w\") as outfile:\n",
        "    json.dump(crime_data, outfile)\n",
        "\n",
        "with open(\"crime_series.json\", \"w\") as outfile:\n",
        "    for record in crime_data:\n",
        "        json.dump(record, outfile)\n",
        "        outfile.write(\"\\n\")\n",
        "\n",
        "with open(\"crime_all.json\") as infile:\n",
        "    crime_data_2 = json.load(infile)\n",
        "\n",
        "crime_data_3 = []\n",
        "with open(\"crime_series.json\") as infile:\n",
        "    for line in infile:\n",
        "        crime_data_3.append(json.loads(line))"
      ],
      "metadata": {
        "cellView": "form",
        "id": "hisYk3eqe03d"
      },
      "execution_count": 21,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "## 22.3.2 XML data"
      ],
      "metadata": {
        "id": "hsDoae79I-VN"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "result = requests.get(\"https://api.worldbank.org/v2/country/CL/indicator/SP.POP.TOTL?format=xml\")\n",
        "pop_data = result.text[3:]\n",
        "print(pop_data)"
      ],
      "metadata": {
        "outputId": "0c65f4b0-161e-4277-c7b7-0ac3320087a3",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "tKku-y6xK_0S",
        "collapsed": true
      },
      "execution_count": 22,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n",
            "<wb:data page=\"1\" pages=\"2\" per_page=\"50\" total=\"64\" sourceid=\"2\" lastupdated=\"2024-11-13\" xmlns:wb=\"http://www.worldbank.org\">\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>2023</wb:date>\r\n",
            "    <wb:value>19629590</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>2022</wb:date>\r\n",
            "    <wb:value>19603733</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>2021</wb:date>\r\n",
            "    <wb:value>19493184</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>2020</wb:date>\r\n",
            "    <wb:value>19300315</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>2019</wb:date>\r\n",
            "    <wb:value>19039485</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>2018</wb:date>\r\n",
            "    <wb:value>18701450</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>2017</wb:date>\r\n",
            "    <wb:value>18368577</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>2016</wb:date>\r\n",
            "    <wb:value>18083879</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>2015</wb:date>\r\n",
            "    <wb:value>17870124</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>2014</wb:date>\r\n",
            "    <wb:value>17687108</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>2013</wb:date>\r\n",
            "    <wb:value>17509925</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>2012</wb:date>\r\n",
            "    <wb:value>17341771</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>2011</wb:date>\r\n",
            "    <wb:value>17173573</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>2010</wb:date>\r\n",
            "    <wb:value>17004162</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>2009</wb:date>\r\n",
            "    <wb:value>16833447</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>2008</wb:date>\r\n",
            "    <wb:value>16661462</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>2007</wb:date>\r\n",
            "    <wb:value>16495538</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>2006</wb:date>\r\n",
            "    <wb:value>16334575</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>2005</wb:date>\r\n",
            "    <wb:value>16175311</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>2004</wb:date>\r\n",
            "    <wb:value>16017966</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>2003</wb:date>\r\n",
            "    <wb:value>15859112</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>2002</wb:date>\r\n",
            "    <wb:value>15693790</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>2001</wb:date>\r\n",
            "    <wb:value>15523978</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>2000</wb:date>\r\n",
            "    <wb:value>15351799</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>1999</wb:date>\r\n",
            "    <wb:value>15176410</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>1998</wb:date>\r\n",
            "    <wb:value>14996742</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>1997</wb:date>\r\n",
            "    <wb:value>14809289</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>1996</wb:date>\r\n",
            "    <wb:value>14615483</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>1995</wb:date>\r\n",
            "    <wb:value>14416796</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>1994</wb:date>\r\n",
            "    <wb:value>14210674</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>1993</wb:date>\r\n",
            "    <wb:value>13998386</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>1992</wb:date>\r\n",
            "    <wb:value>13782297</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>1991</wb:date>\r\n",
            "    <wb:value>13561945</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>1990</wb:date>\r\n",
            "    <wb:value>13342868</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>1989</wb:date>\r\n",
            "    <wb:value>13128619</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>1988</wb:date>\r\n",
            "    <wb:value>12918389</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>1987</wb:date>\r\n",
            "    <wb:value>12712784</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>1986</wb:date>\r\n",
            "    <wb:value>12514502</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>1985</wb:date>\r\n",
            "    <wb:value>12326396</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>1984</wb:date>\r\n",
            "    <wb:value>12147758</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>1983</wb:date>\r\n",
            "    <wb:value>11976513</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>1982</wb:date>\r\n",
            "    <wb:value>11807408</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>1981</wb:date>\r\n",
            "    <wb:value>11637613</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>1980</wb:date>\r\n",
            "    <wb:value>11469828</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>1979</wb:date>\r\n",
            "    <wb:value>11304331</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>1978</wb:date>\r\n",
            "    <wb:value>11137748</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>1977</wb:date>\r\n",
            "    <wb:value>10969861</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>1976</wb:date>\r\n",
            "    <wb:value>10804869</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>1975</wb:date>\r\n",
            "    <wb:value>10639531</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "  <wb:data>\r\n",
            "    <wb:indicator id=\"SP.POP.TOTL\">Population, total</wb:indicator>\r\n",
            "    <wb:country id=\"CL\">Chile</wb:country>\r\n",
            "    <wb:countryiso3code>CHL</wb:countryiso3code>\r\n",
            "    <wb:date>1974</wb:date>\r\n",
            "    <wb:value>10472743</wb:value>\r\n",
            "    <wb:unit />\r\n",
            "    <wb:obs_status />\r\n",
            "    <wb:decimal>0</wb:decimal>\r\n",
            "  </wb:data>\r\n",
            "</wb:data>\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "! pip install xmltodict"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "63rwDU6AMLyA",
        "outputId": "bebbeb2c-17f9-4e06-b42f-0bdba323db3a"
      },
      "execution_count": 23,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Collecting xmltodict\n",
            "  Downloading xmltodict-0.14.2-py2.py3-none-any.whl.metadata (8.0 kB)\n",
            "Downloading xmltodict-0.14.2-py2.py3-none-any.whl (10.0 kB)\n",
            "Installing collected packages: xmltodict\n",
            "Successfully installed xmltodict-0.14.2\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "import xmltodict\n",
        "population = xmltodict.parse(pop_data)\n",
        "population"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "_6jV8ZxZHOZL",
        "outputId": "f3673a72-ab08-4455-f8c0-1fb172aea92f",
        "collapsed": true
      },
      "execution_count": 25,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "{'wb:data': {'@page': '1',\n",
              "  '@pages': '2',\n",
              "  '@per_page': '50',\n",
              "  '@total': '64',\n",
              "  '@sourceid': '2',\n",
              "  '@lastupdated': '2024-11-13',\n",
              "  '@xmlns:wb': 'http://www.worldbank.org',\n",
              "  'wb:data': [{'wb:indicator': {'@id': 'SP.POP.TOTL',\n",
              "     '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '2023',\n",
              "    'wb:value': '19629590',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '2022',\n",
              "    'wb:value': '19603733',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '2021',\n",
              "    'wb:value': '19493184',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '2020',\n",
              "    'wb:value': '19300315',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '2019',\n",
              "    'wb:value': '19039485',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '2018',\n",
              "    'wb:value': '18701450',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '2017',\n",
              "    'wb:value': '18368577',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '2016',\n",
              "    'wb:value': '18083879',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '2015',\n",
              "    'wb:value': '17870124',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '2014',\n",
              "    'wb:value': '17687108',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '2013',\n",
              "    'wb:value': '17509925',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '2012',\n",
              "    'wb:value': '17341771',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '2011',\n",
              "    'wb:value': '17173573',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '2010',\n",
              "    'wb:value': '17004162',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '2009',\n",
              "    'wb:value': '16833447',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '2008',\n",
              "    'wb:value': '16661462',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '2007',\n",
              "    'wb:value': '16495538',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '2006',\n",
              "    'wb:value': '16334575',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '2005',\n",
              "    'wb:value': '16175311',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '2004',\n",
              "    'wb:value': '16017966',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '2003',\n",
              "    'wb:value': '15859112',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '2002',\n",
              "    'wb:value': '15693790',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '2001',\n",
              "    'wb:value': '15523978',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '2000',\n",
              "    'wb:value': '15351799',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '1999',\n",
              "    'wb:value': '15176410',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '1998',\n",
              "    'wb:value': '14996742',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '1997',\n",
              "    'wb:value': '14809289',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '1996',\n",
              "    'wb:value': '14615483',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '1995',\n",
              "    'wb:value': '14416796',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '1994',\n",
              "    'wb:value': '14210674',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '1993',\n",
              "    'wb:value': '13998386',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '1992',\n",
              "    'wb:value': '13782297',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '1991',\n",
              "    'wb:value': '13561945',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '1990',\n",
              "    'wb:value': '13342868',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '1989',\n",
              "    'wb:value': '13128619',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '1988',\n",
              "    'wb:value': '12918389',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '1987',\n",
              "    'wb:value': '12712784',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '1986',\n",
              "    'wb:value': '12514502',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '1985',\n",
              "    'wb:value': '12326396',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '1984',\n",
              "    'wb:value': '12147758',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '1983',\n",
              "    'wb:value': '11976513',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '1982',\n",
              "    'wb:value': '11807408',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '1981',\n",
              "    'wb:value': '11637613',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '1980',\n",
              "    'wb:value': '11469828',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '1979',\n",
              "    'wb:value': '11304331',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '1978',\n",
              "    'wb:value': '11137748',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '1977',\n",
              "    'wb:value': '10969861',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '1976',\n",
              "    'wb:value': '10804869',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '1975',\n",
              "    'wb:value': '10639531',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'},\n",
              "   {'wb:indicator': {'@id': 'SP.POP.TOTL', '#text': 'Population, total'},\n",
              "    'wb:country': {'@id': 'CL', '#text': 'Chile'},\n",
              "    'wb:countryiso3code': 'CHL',\n",
              "    'wb:date': '1974',\n",
              "    'wb:value': '10472743',\n",
              "    'wb:unit': None,\n",
              "    'wb:obs_status': None,\n",
              "    'wb:decimal': '0'}]}}"
            ]
          },
          "metadata": {},
          "execution_count": 25
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "### Try This: Fetching and Parsing XML\n",
        "Write the code to pull the XML data for Chile’s population from http://mng.bz/103V. Then use `xmltodict` to parse the XML into a Python dictionary and report how much Chile's population changed in the past 25 years."
      ],
      "metadata": {
        "id": "ft6lKBx0fSMk"
      }
    },
    {
      "cell_type": "code",
      "source": [],
      "metadata": {
        "id": "CmvRGX1LfoTg"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# @title\n",
        "import requests\n",
        "import xmltodict\n",
        "\n",
        "result = requests.get(\"https://api.worldbank.org/v2/country/CL/indicator/SP.POP.TOTL?format=xml\")\n",
        "pop_data = result.text[3:]\n",
        "population = xmltodict.parse(pop_data)\n",
        "start_population = population['wb:data']['wb:data'][25]\n",
        "current_population = population['wb:data']['wb:data'][0]\n",
        "print(f\"Popluation change from {start_population['wb:date']} to {current_population['wb:date']}: {int(current_population['wb:value']) - int(start_population['wb:value'])}\")\n",
        "\n"
      ],
      "metadata": {
        "cellView": "form",
        "id": "Nto4IRwTfocl"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "# 22.4 Scraping web data"
      ],
      "metadata": {
        "id": "_QIfMynfkQ4k"
      }
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "utMKUiT-k0jt",
        "outputId": "05098b24-8566-4b1b-8be6-17242b6091d5",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "source": [
        "%%writefile test.html\n",
        "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n",
        "<html> <head>\n",
        "<title>Title</title>\n",
        "</head>\n",
        "\n",
        "<body>\n",
        "<h1>Heading 1</h1>\n",
        "\n",
        "This is plan text, and is boring\n",
        "<span class=\"special\">this is special</span>\n",
        "\n",
        "Here is a <a href=\"http://bitbucket.dev.null\">link</a>\n",
        "\n",
        "<hr>\n",
        "<address>Ann Address, Somewhere, AState 00000\n",
        "</address>\n",
        "</body> </html>"
      ],
      "execution_count": 35,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Writing test.html\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "iTCvHMhGk0ju"
      },
      "source": [
        "import bs4\n",
        "html = open(\"test.html\").read()\n",
        "bs = bs4.BeautifulSoup(html, \"html.parser\")"
      ],
      "execution_count": 36,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Pg_90xHCk0ju",
        "outputId": "e1110846-4491-4bc8-9e34-46a96a1d3802",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "source": [
        "a_list = bs(\"a\")\n",
        "print(a_list)"
      ],
      "execution_count": 37,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[<a href=\"http://bitbucket.dev.null\">link</a>]\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Recz_Fdak0jv",
        "outputId": "dcc9b951-9d89-4746-d230-0664987fc293",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "a_item = a_list[0]\n",
        "a_item.text"
      ],
      "execution_count": 38,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "'link'"
            ],
            "application/vnd.google.colaboratory.intrinsic+json": {
              "type": "string"
            }
          },
          "metadata": {},
          "execution_count": 38
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Jk5InTOAk0jv",
        "outputId": "31224a67-f087-4185-8aa4-372c809525ff",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "a_item[\"href\"]"
      ],
      "execution_count": 39,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "'http://bitbucket.dev.null'"
            ],
            "application/vnd.google.colaboratory.intrinsic+json": {
              "type": "string"
            }
          },
          "metadata": {},
          "execution_count": 39
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "xlk2pyqJk0jv",
        "outputId": "0d8e48a8-0fab-4843-cb39-9dc68dd2162e",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "source": [
        "special_list = bs.select(\".special\")\n",
        "print(special_list)"
      ],
      "execution_count": 40,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[<span class=\"special\">this is special</span>]\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "koTgZn2wk0jw",
        "outputId": "2bad4ce0-ce82-46cc-be9c-65479515f115",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "special_item = special_list[0]\n",
        "special_item.text"
      ],
      "execution_count": 41,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "'this is special'"
            ],
            "application/vnd.google.colaboratory.intrinsic+json": {
              "type": "string"
            }
          },
          "metadata": {},
          "execution_count": 41
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "V-pjGocXk0jw",
        "outputId": "3571a434-6a37-408d-877a-294c88a1804e",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "source": [
        "special_item[\"class\"]"
      ],
      "execution_count": 42,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "['special']"
            ]
          },
          "metadata": {},
          "execution_count": 42
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "### Try This: Parsing HTML\n",
        "Given the file `forecast.html` (which you can create by executing the cell below), write a script using Beautiful Soup that extracts the data and saves it as a CSV file, shown here."
      ],
      "metadata": {
        "id": "ee-yeZA2keEQ"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "%%writefile forecast.html\n",
        "<html>\n",
        "  <body>\n",
        "    <div class=\"row row-forecast\">\n",
        "        <div class=\"grid col-25 forecast-label\"><b>Tonight</b></div>\n",
        "        <div class=\"grid col-75 forecast-text\">A slight chance of showers and thunderstorms before 10pm. Mostly cloudy, with a low around 66. West southwest wind around 9 mph. Chance of precipitation is 20%. New rainfall amounts between a tenth and quarter of an inch possible.</div>\n",
        "    </div>\n",
        "    <div class=\"row row-forecast\">\n",
        "        <div class=\"grid col-25 forecast-label\"><b>Friday</b></div>\n",
        "        <div class=\"grid col-75 forecast-text\">Partly sunny. High near 77, with temperatures falling to around 75 in the afternoon. Northwest wind 7 to 12 mph, with gusts as high as 18 mph.</div>\n",
        "    </div>\n",
        "    <div class=\"row row-forecast\">\n",
        "        <div class=\"grid col-25 forecast-label\"><b>Friday Night</b></div>\n",
        "        <div class=\"grid col-75 forecast-text\">Mostly cloudy, with a low around 63. North wind 7 to 10 mph.</div>\n",
        "    </div>\n",
        "    <div class=\"row row-forecast\">\n",
        "        <div class=\"grid col-25 forecast-label\"><b>Saturday</b></div>\n",
        "        <div class=\"grid col-75 forecast-text\">Mostly sunny, with a high near 73. North wind around 10 mph.</div>\n",
        "    </div>\n",
        "    <div class=\"row row-forecast\">\n",
        "        <div class=\"grid col-25 forecast-label\"><b>Saturday Night</b></div>\n",
        "        <div class=\"grid col-75 forecast-text\">Partly cloudy, with a low around 63. North wind 5 to 10 mph.</div>\n",
        "    </div>\n",
        "    <div class=\"row row-forecast\">\n",
        "        <div class=\"grid col-25 forecast-label\"><b>Sunday</b></div>\n",
        "        <div class=\"grid col-75 forecast-text\">Mostly sunny, with a high near 73.</div>\n",
        "    </div>\n",
        "    <div class=\"row row-forecast\">\n",
        "        <div class=\"grid col-25 forecast-label\"><b>Sunday Night</b></div>\n",
        "        <div class=\"grid col-75 forecast-text\">Mostly cloudy, with a low around 64.</div>\n",
        "    </div>\n",
        "    <div class=\"row row-forecast\">\n",
        "        <div class=\"grid col-25 forecast-label\"><b>Monday</b></div>\n",
        "        <div class=\"grid col-75 forecast-text\">Mostly sunny, with a high near 74.</div>\n",
        "    </div>\n",
        "    <div class=\"row row-forecast\">\n",
        "        <div class=\"grid col-25 forecast-label\"><b>Monday Night</b></div>\n",
        "        <div class=\"grid col-75 forecast-text\">Mostly clear, with a low around 65.</div>\n",
        "    </div>\n",
        "    <div class=\"row row-forecast\">\n",
        "        <div class=\"grid col-25 forecast-label\"><b>Tuesday</b></div>\n",
        "        <div class=\"grid col-75 forecast-text\">Sunny, with a high near 75.</div>\n",
        "    </div>\n",
        "    <div class=\"row row-forecast\">\n",
        "        <div class=\"grid col-25 forecast-label\"><b>Tuesday Night</b></div>\n",
        "        <div class=\"grid col-75 forecast-text\">Mostly clear, with a low around 65.</div>\n",
        "    </div>\n",
        "    <div class=\"row row-forecast\">\n",
        "        <div class=\"grid col-25 forecast-label\"><b>Wednesday</b></div>\n",
        "        <div class=\"grid col-75 forecast-text\">Sunny, with a high near 77.</div>\n",
        "    </div>\n",
        "    <div class=\"row row-forecast\">\n",
        "        <div class=\"grid col-25 forecast-label\"><b>Wednesday Night</b></div>\n",
        "        <div class=\"grid col-75 forecast-text\">Mostly clear, with a low around 67.</div>\n",
        "    </div>\n",
        "    <div class=\"row row-forecast\">\n",
        "        <div class=\"grid col-25 forecast-label\"><b>Thursday</b></div>\n",
        "        <div class=\"grid col-75 forecast-text\">A chance of rain showers after 1pm. Mostly sunny, with a high near 81. Chance of precipitation is 30%.</div>\n",
        "    </div>\n",
        "  </body>\n",
        "</html>"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "wiJa2ZgqE9u9",
        "outputId": "6100c75f-8b7c-4c20-f6ed-ad4d0f87e97f"
      },
      "execution_count": 43,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Writing forecast.html\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [],
      "metadata": {
        "id": "1s7N4kKRFDIp"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# @title\n",
        "import csv\n",
        "import bs4\n",
        "\n",
        "def read_html(filename):\n",
        "    with open(filename) as html_file:\n",
        "        html = html_file.read()\n",
        "        return html\n",
        "\n",
        "\n",
        "def parse_html(html):\n",
        "    bs = bs4.BeautifulSoup(html, \"html.parser\")\n",
        "    labels = [x.text for x in bs.select(\".forecast-label\")]\n",
        "    forecasts = [x.text for x in bs.select(\".forecast-text\")]\n",
        "\n",
        "    return list(zip(labels, forecasts))\n",
        "\n",
        "def write_to_csv(data, outfilename):\n",
        "    csv.writer(open(outfilename, \"w\")).writerows(data)\n",
        "\n",
        "if __name__ == '__main__':\n",
        "    html = read_html(\"forecast.html\")\n",
        "    values = parse_html(html)\n",
        "    write_to_csv(values, \"forecast.csv\")\n",
        "    print(values)"
      ],
      "metadata": {
        "cellView": "form",
        "id": "0GEpgvAWkuP3"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "# Lab 22.5  Track the weather"
      ],
      "metadata": {
        "id": "zBEaC5UzqzVq"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "Use the API described in section 22.2 to gather a history of the mean temperatures of a location (you can use Chicago as above or supply the latitude and longitude for a different location) for a month. You will need to use a slightly different URL for the archive API: `https://archive-api.open-meteo.com/v1/era5?latitude=<latitude>&longitude=<longitude>&start_date=<YYYY-MM-DD>&end_date=<YYYY-MM-DD>&daily=temperature_2m_mean` like this:\n",
        "\n",
        "```python\n",
        "https://archive-api.open-meteo.com/v1/era5?latitude=41.879&longitude=-87.64975&start_date=2024-07-01&end_date=2024-07-31&daily=temperature_2m_mean\n",
        "```\n",
        "Notice that you will get two lists - a list of the dates and a matching list o f the mean temperatures in Celsius for those dates. Transform the data so that you can load it into a spreadsheet and graph it.  \n",
        "\n",
        "**HINT:** Remember that spreadsheets can read CSV files, so you don't need to create an Excel file."
      ],
      "metadata": {
        "id": "-xpnWP3JEzWT"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "## Human solution"
      ],
      "metadata": {
        "id": "zSktJq7ALlYH"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "import requests\n",
        "import csv\n",
        "response = requests.get(\"https://archive-api.open-meteo.com/v1/era5?latitude=41.879&longitude=-87.64975&start_date=2024-07-01&end_date=2024-07-31&daily=temperature_2m_mean\")\n",
        "weather_history = response.json()\n",
        "weather_history\n"
      ],
      "metadata": {
        "id": "VbcniA9cq7Us",
        "outputId": "f148e56d-b242-42f0-8398-9999522a23d2",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "{'latitude': 41.862915,\n",
              " 'longitude': -87.64877,\n",
              " 'generationtime_ms': 0.04601478576660156,\n",
              " 'utc_offset_seconds': 0,\n",
              " 'timezone': 'GMT',\n",
              " 'timezone_abbreviation': 'GMT',\n",
              " 'elevation': 186.0,\n",
              " 'daily_units': {'time': 'iso8601', 'temperature_2m_mean': '°C'},\n",
              " 'daily': {'time': ['2024-07-01',\n",
              "   '2024-07-02',\n",
              "   '2024-07-03',\n",
              "   '2024-07-04',\n",
              "   '2024-07-05',\n",
              "   '2024-07-06',\n",
              "   '2024-07-07',\n",
              "   '2024-07-08',\n",
              "   '2024-07-09',\n",
              "   '2024-07-10',\n",
              "   '2024-07-11',\n",
              "   '2024-07-12',\n",
              "   '2024-07-13',\n",
              "   '2024-07-14',\n",
              "   '2024-07-15',\n",
              "   '2024-07-16',\n",
              "   '2024-07-17',\n",
              "   '2024-07-18',\n",
              "   '2024-07-19',\n",
              "   '2024-07-20',\n",
              "   '2024-07-21',\n",
              "   '2024-07-22',\n",
              "   '2024-07-23',\n",
              "   '2024-07-24',\n",
              "   '2024-07-25',\n",
              "   '2024-07-26',\n",
              "   '2024-07-27',\n",
              "   '2024-07-28',\n",
              "   '2024-07-29',\n",
              "   '2024-07-30',\n",
              "   '2024-07-31'],\n",
              "  'temperature_2m_mean': [16.8,\n",
              "   21.2,\n",
              "   25.7,\n",
              "   24.0,\n",
              "   23.2,\n",
              "   21.0,\n",
              "   22.8,\n",
              "   24.8,\n",
              "   22.8,\n",
              "   21.4,\n",
              "   20.7,\n",
              "   21.6,\n",
              "   23.9,\n",
              "   25.9,\n",
              "   25.9,\n",
              "   25.3,\n",
              "   22.7,\n",
              "   19.2,\n",
              "   19.3,\n",
              "   20.8,\n",
              "   21.6,\n",
              "   21.8,\n",
              "   23.0,\n",
              "   21.2,\n",
              "   20.3,\n",
              "   20.5,\n",
              "   22.6,\n",
              "   23.4,\n",
              "   23.8,\n",
              "   24.6,\n",
              "   26.2]}}"
            ]
          },
          "metadata": {},
          "execution_count": 1
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "\n",
        "weather_data = zip(weather_history[\"daily\"][\"time\"], weather_history[\"daily\"][\"temperature_2m_mean\"])\n",
        "list(weather_data)\n"
      ],
      "metadata": {
        "id": "XQzgic3DOUCp",
        "outputId": "d6628a57-65c6-430b-f39f-39736a31b7a3",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "[('2024-07-01', 16.8),\n",
              " ('2024-07-02', 21.2),\n",
              " ('2024-07-03', 25.7),\n",
              " ('2024-07-04', 24.0),\n",
              " ('2024-07-05', 23.2),\n",
              " ('2024-07-06', 21.0),\n",
              " ('2024-07-07', 22.8),\n",
              " ('2024-07-08', 24.8),\n",
              " ('2024-07-09', 22.8),\n",
              " ('2024-07-10', 21.4),\n",
              " ('2024-07-11', 20.7),\n",
              " ('2024-07-12', 21.6),\n",
              " ('2024-07-13', 23.9),\n",
              " ('2024-07-14', 25.9),\n",
              " ('2024-07-15', 25.9),\n",
              " ('2024-07-16', 25.3),\n",
              " ('2024-07-17', 22.7),\n",
              " ('2024-07-18', 19.2),\n",
              " ('2024-07-19', 19.3),\n",
              " ('2024-07-20', 20.8),\n",
              " ('2024-07-21', 21.6),\n",
              " ('2024-07-22', 21.8),\n",
              " ('2024-07-23', 23.0),\n",
              " ('2024-07-24', 21.2),\n",
              " ('2024-07-25', 20.3),\n",
              " ('2024-07-26', 20.5),\n",
              " ('2024-07-27', 22.6),\n",
              " ('2024-07-28', 23.4),\n",
              " ('2024-07-29', 23.8),\n",
              " ('2024-07-30', 24.6),\n",
              " ('2024-07-31', 26.2)]"
            ]
          },
          "metadata": {},
          "execution_count": 4
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "with open(\"weather_history.csv\", \"w\", newline=\"\") as file:\n",
        "    writer = csv.writer(file)\n",
        "    writer.writerow([\"Date\", \"Temperature\"])\n",
        "    writer.writerows(weather_data)\n",
        "\n"
      ],
      "metadata": {
        "id": "vvmoMY6AOZfJ"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "### Remaining steps\n",
        "\n",
        "1. Download weather_history.csv to your machine.\n",
        "2. Import weather_history.cvs into a spreadsheet (e.g. Google sheets or Excel)\n",
        "3. Select data and insert chart. (creating a graph may be somewhat different in different applications.)\n",
        "\n",
        "![Lab_22_2024-10-17_20-25-08.png]()"
      ],
      "metadata": {
        "id": "KgUfon5qHHwU"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "## Copilot solution"
      ],
      "metadata": {
        "id": "ERnn6SOeLpkY"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "### Prompt\n",
        "\n",
        "The URL https://archive-api.open-meteo.com/v1/era5?latitude=41.879&longitude=-87.64975&start_date=2024-07-01&end_date=2024-07-31&daily=temperature_2m_mean will return one day’s weather data for Chicago in JSON format. The data will contain a “daily” field with two lists, “time” and “temperature_2m_mean”. Download the data and save the time and temperature_2m_mean fields into a CSV file that can later be loaded into a spreadsheet and graphed.\n"
      ],
      "metadata": {
        "id": "GyF3Is4jg75o"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "import requests\n",
        "import csv\n",
        "\n",
        "# URL to fetch the weather data\n",
        "url = \"https://archive-api.open-meteo.com/v1/era5?latitude=41.879&longitude=-87.64975&start_date=2024-07-01&end_date=2024-07-31&daily=temperature_2m_mean\"\n",
        "\n",
        "# Fetch the data\n",
        "response = requests.get(url)\n",
        "data = response.json()\n",
        "\n",
        "# Extract the relevant fields\n",
        "time_data = data['daily']['time']\n",
        "temperature_data = data['daily']['temperature_2m_mean']\n",
        "\n",
        "# Output CSV file\n",
        "output_file = 'Chicago_weather_July_2024.csv'\n",
        "\n",
        "# Write the data to the CSV file\n",
        "with open(output_file, 'w', newline='') as csvfile:\n",
        "    writer = csv.writer(csvfile)\n",
        "    writer.writerow(['Date', 'Temperature (°C)'])  # Write the header\n",
        "    for time, temperature in zip(time_data, temperature_data):\n",
        "        writer.writerow([time, temperature])"
      ],
      "metadata": {
        "id": "rYAFbr-Psibl"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "## Colaboratory solution"
      ],
      "metadata": {
        "id": "Xfj9_lpaLsQ9"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "### Prompt\n",
        "\n",
        "The URL https://archive-api.open-meteo.com/v1/era5?latitude=41.879&longitude=-87.64975&start_date=2024-07-01&end_date=2024-07-31&daily=temperature_2m_mean will return one day’s weather data for Chicago in JSON format. The data will contain a “daily” field with two lists, “time” and “temperature_2m_mean”. Download the data and save the time and temperature_2m_mean fields into a CSV file that can later be loaded into a spreadsheet and graphed.\n"
      ],
      "metadata": {
        "id": "Aygl6DjshEG9"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# prompt: The URL https://archive-api.open-meteo.com/v1/era5?latitude=41.879&longitude=-87.64975&start_date=2024-07-01&end_date=2024-07-31&daily=temperature_2m_mean\n",
        "#         will return one day’s weather data for Chicago in JSON format. The\n",
        "#         data will contain a “daily” field with two lists, “time” and\n",
        "#         “temperature_2m_mean”. Download the data and save the time and\n",
        "#         temperature_2m_mean fields into a CSV file that can later be loaded\n",
        "#         into a spreadsheet and graphed.\n",
        "\n",
        "import csv\n",
        "import requests\n",
        "\n",
        "def download_and_save_chicago_weather():\n",
        "  \"\"\"Downloads Chicago weather data and saves it to a CSV file.\"\"\"\n",
        "\n",
        "  url = \"https://archive-api.open-meteo.com/v1/era5?latitude=41.879&longitude=-87.64975&start_date=2024-07-01&end_date=2024-07-31&daily=temperature_2m_mean\"\n",
        "  response = requests.get(url)\n",
        "  if response.status_code == 200:\n",
        "    weather_data = response.json()\n",
        "\n",
        "    if \"daily\" in weather_data:\n",
        "      daily_data = weather_data[\"daily\"]\n",
        "      if \"time\" in daily_data and \"temperature_2m_mean\" in daily_data:\n",
        "        with open('chicago_weather_july.csv', 'w', newline='') as outfile:\n",
        "          writer = csv.writer(outfile)\n",
        "          writer.writerow(['Date', 'Mean Temperature (°C)'])  # Write header row\n",
        "          for i in range(len(daily_data[\"time\"])):\n",
        "            writer.writerow([daily_data[\"time\"][i], daily_data[\"temperature_2m_mean\"][i]])\n",
        "        print(\"Chicago weather data for July 2024 saved to chicago_weather_july.csv\")\n",
        "      else:\n",
        "        print(\"Error: 'time' or 'temperature_2m_mean' not found in daily data.\")\n",
        "    else:\n",
        "      print(\"Error: 'daily' field not found in weather data.\")\n",
        "  else:\n",
        "    print(\"Error downloading data:\", response.status_code)\n",
        "\n",
        "\n",
        "download_and_save_chicago_weather()"
      ],
      "metadata": {
        "id": "MYbdt8oPLuYL",
        "outputId": "1bde4199-96fa-4a7f-dbb7-68e3d198608e",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Chicago weather data for July 2024 saved to chicago_weather_july.csv\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [],
      "metadata": {
        "id": "vrcyISBliDVk"
      },
      "execution_count": null,
      "outputs": []
    }
  ]
}